From 5327444e834f30945e15b51d4cc060b9027d9e93 Mon Sep 17 00:00:00 2001 From: Masaya Takahashi Date: Thu, 7 Jan 2021 11:34:55 +0900 Subject: [PATCH 1/3] ANDROID: GKI: Add Sony KMI symbol list add initial abi_gki_aarch64_sony file. Leaf changes summary: 5 artifacts changed Changed leaf types summary: 0 leaf type changed Removed/Changed/Added functions summary: 0 Removed, 0 Changed, 5 Added functions Removed/Changed/Added variables summary: 0 Removed, 0 Changed, 0 Added variable 5 Added functions: [A] 'function gpio_desc* devm_gpiod_get_from_of_node(device*, device_node*, const char*, int, gpiod_flags, const char*)' [A] 'function void devm_gpiod_unhinge(device*, gpio_desc*)' [A] 'function const char* devm_kstrdup_const(device*, const char*, gfp_t)' [A] 'function void led_trigger_blink_oneshot(led_trigger*, unsigned long int*, unsigned long int*, int)' [A] 'function int request_any_context_irq(unsigned int, irq_handler_t, unsigned long int, const char*, void*)' Bug: 176874947 Change-Id: Ic17a468ed326e94263e636df6ca75b2fbcced7f6 Signed-off-by: Masaya Takahashi --- android/abi_gki_aarch64.xml | 2097 +++++++++++++++++++--------------- android/abi_gki_aarch64_sony | 40 + build.config.gki.aarch64 | 1 + 3 files changed, 1209 insertions(+), 929 deletions(-) create mode 100644 android/abi_gki_aarch64_sony diff --git a/android/abi_gki_aarch64.xml b/android/abi_gki_aarch64.xml index 1f89d3ac2614..78ce1e136f6f 100644 --- a/android/abi_gki_aarch64.xml +++ b/android/abi_gki_aarch64.xml @@ -979,9 +979,11 @@ + + @@ -996,6 +998,7 @@ + @@ -2279,6 +2282,7 @@ + @@ -3159,6 +3163,7 @@ + @@ -17771,6 +17776,7 @@ + @@ -17782,7 +17788,6 @@ - @@ -23179,6 +23184,12 @@ + + + + + + @@ -23917,6 +23928,14 @@ + + + + + + + + @@ -23949,14 +23968,6 @@ - - - - - - - - @@ -31508,11 +31519,25 @@ + + + + + + + + + + + + + + @@ -46875,6 +46900,15 @@ + + + + + + + + + @@ -55664,17 +55698,6 @@ - - - - - - - - - - - @@ -56534,42 +56557,42 @@ - + - + - + - + - + - + - + @@ -56953,14 +56976,6 @@ - - - - - - - - @@ -90385,14 +90400,6 @@ - - - - - - - - @@ -92459,7 +92466,7 @@ - + @@ -94176,6 +94183,14 @@ + + + + + + + + @@ -109984,268 +109999,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -110322,7 +110078,7 @@ - + @@ -110368,27 +110124,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + @@ -110573,13 +110344,6 @@ - - - - - - - @@ -110587,10 +110351,6 @@ - - - - @@ -111511,32 +111271,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -113349,24 +113083,249 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - + + + + + + + - + + + + + + + + + @@ -114591,7 +114550,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -114599,7 +114588,7 @@ - + @@ -115458,7 +115447,7 @@ - + @@ -115622,7 +115611,7 @@ - + @@ -116320,6 +116309,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -116398,149 +116473,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -116552,7 +116484,7 @@ - + @@ -116785,42 +116717,23 @@ - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - + @@ -119559,6 +119472,25 @@ + + + + + + + + + + + + + + + + + + + @@ -120362,282 +120294,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -120691,91 +120347,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -120790,6 +120361,24 @@ + + + + + + + + + + + + + + + + + + @@ -120892,6 +120481,29 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -121162,6 +120774,334 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -121176,7 +121116,7 @@ - + @@ -121205,7 +121145,7 @@ - + @@ -121797,7 +121737,7 @@ - + @@ -122485,7 +122425,7 @@ - + @@ -122757,7 +122697,7 @@ - + @@ -123535,7 +123475,6 @@ - @@ -123561,12 +123500,12 @@ - + - + @@ -124050,70 +123989,70 @@ - + - + - + - + - + - + - + - + - + - + - + @@ -124121,13 +124060,13 @@ - + - + @@ -124136,13 +124075,13 @@ - + - + @@ -124179,25 +124118,25 @@ - + - + - + - + @@ -124207,7 +124146,7 @@ - + @@ -124220,6 +124159,237 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -124227,6 +124397,17 @@ + + + + + + + + + + + @@ -124269,7 +124450,7 @@ - + @@ -124277,8 +124458,27 @@ + + + + + + + + + + + + + + + + + + + @@ -124754,7 +124954,7 @@ - + @@ -124786,7 +124986,7 @@ - + @@ -124794,7 +124994,7 @@ - + @@ -124822,7 +125022,7 @@ - + @@ -125106,7 +125306,7 @@ - + @@ -125226,7 +125426,7 @@ - + @@ -125746,6 +125946,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -125761,6 +125999,7 @@ + diff --git a/android/abi_gki_aarch64_sony b/android/abi_gki_aarch64_sony new file mode 100644 index 000000000000..47428a566c02 --- /dev/null +++ b/android/abi_gki_aarch64_sony @@ -0,0 +1,40 @@ +[abi_symbol_list] + devm_gpiod_get_from_of_node + devm_gpiod_unhinge + devm_kstrdup_const + devm_mfd_add_devices + down_timeout + filp_close + filp_open + find_vpid + input_mt_destroy_slots + led_trigger_blink_oneshot + nr_irqs + pid_task + rdev_get_id + regcache_drop_region + regmap_async_complete + regmap_multi_reg_write + regmap_multi_reg_write + regmap_multi_reg_write_bypassed + regmap_raw_write + regmap_raw_write_async + regulator_bulk_enable + regulator_disable_regmap + regulator_enable_regmap + regulator_get_voltage_sel_regmap + regulator_is_enabled_regmap + regulator_map_voltage_linear + regulator_set_voltage_sel_regmap + request_any_context_irq + snd_compr_stop_error + snd_pcm_format_physical_width + snd_soc_component_disable_pin + snd_soc_component_force_enable_pin + snd_soc_component_set_sysclk + snd_soc_get_volsw_range + snd_soc_info_volsw_range + snd_soc_put_volsw_range + spi_bus_type + strncat + thermal_zone_device_unregister diff --git a/build.config.gki.aarch64 b/build.config.gki.aarch64 index 58ea308926f0..2c8a87684413 100644 --- a/build.config.gki.aarch64 +++ b/build.config.gki.aarch64 @@ -15,6 +15,7 @@ android/abi_gki_aarch64_hikey960 android/abi_gki_aarch64_oneplus android/abi_gki_aarch64_oplus android/abi_gki_aarch64_qcom +android/abi_gki_aarch64_sony android/abi_gki_aarch64_sunxi android/abi_gki_aarch64_unisoc android/abi_gki_aarch64_vivo From fec1dfacf24794ff2f53158951c5c187868b4531 Mon Sep 17 00:00:00 2001 From: Todd Kjos Date: Wed, 13 Jan 2021 14:09:53 -0800 Subject: [PATCH 2/3] ANDROID: simplify vendor hooks for non-GKI builds Vendor hooks required explicitly defining macros or inline functions to handle the non-GKI build case (!CONFIG_ANDROID_VENDOR_HOOKS). Added support for generating them automatically so the macros are no longer required. Both models are now supported so we can transition. Bug: 177416721 Signed-off-by: Todd Kjos Change-Id: I01acc389d315a5d509b0c48116854342a42e1058 --- include/trace/hooks/sched.h | 20 +++----------------- include/trace/hooks/vendor_hooks.h | 9 +++++++++ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/include/trace/hooks/sched.h b/include/trace/hooks/sched.h index 4e2be4d70658..a2f5b45dd6f9 100644 --- a/include/trace/hooks/sched.h +++ b/include/trace/hooks/sched.h @@ -10,7 +10,6 @@ * Following tracepoints are not exported in tracefs and provide a * mechanism for vendor modules to hook and extend functionality */ -#if defined(CONFIG_TRACEPOINTS) && defined(CONFIG_ANDROID_VENDOR_HOOKS) struct task_struct; DECLARE_RESTRICTED_HOOK(android_rvh_select_task_rq_fair, TP_PROTO(struct task_struct *p, int prev_cpu, int sd_flag, int wake_flags, int *new_cpu), @@ -70,22 +69,9 @@ struct sched_group; DECLARE_RESTRICTED_HOOK(android_rvh_find_busiest_group, TP_PROTO(struct sched_group *busiest, struct rq *dst_rq, int *out_balance), TP_ARGS(busiest, dst_rq, out_balance), 1); -#else -#define trace_android_rvh_select_task_rq_fair(p, prev_cpu, sd_flag, wake_flags, new_cpu) -#define trace_android_rvh_select_task_rq_rt(p, prev_cpu, sd_flag, wake_flags, new_cpu) -#define trace_android_rvh_select_fallback_rq(cpu, p, dest_cpu) -#define trace_android_vh_scheduler_tick(rq) -#define trace_android_rvh_enqueue_task(rq, p) -#define trace_android_rvh_dequeue_task(rq, p) -#define trace_android_rvh_can_migrate_task(p, dst_cpu, can_migrate) -#define trace_android_rvh_find_lowest_rq(p, local_cpu_mask, lowest_cpu) -#define trace_android_rvh_prepare_prio_fork(p) -#define trace_android_rvh_finish_prio_fork(p) -#define trace_android_rvh_rtmutex_prepare_setprio(p, pi_task) -#define trace_android_rvh_set_user_nice(p, nice) -#define trace_android_rvh_setscheduler(p) -#define trace_android_rvh_find_busiest_group(busiest, dst_rq, out_balance) -#endif + +/* macro versions of hooks are no longer required */ + #endif /* _TRACE_HOOK_SCHED_H */ /* This part must be outside protection */ #include diff --git a/include/trace/hooks/vendor_hooks.h b/include/trace/hooks/vendor_hooks.h index 8a3fdb9222e5..eea881975d35 100644 --- a/include/trace/hooks/vendor_hooks.h +++ b/include/trace/hooks/vendor_hooks.h @@ -9,6 +9,8 @@ #include +#if defined(CONFIG_TRACEPOINTS) && defined(CONFIG_ANDROID_VENDOR_HOOKS) + #define DECLARE_HOOK DECLARE_TRACE #ifdef TRACE_HEADER_MULTI_READ @@ -74,3 +76,10 @@ PARAMS(__data, args)) #endif /* TRACE_HEADER_MULTI_READ */ + +#else /* !CONFIG_TRACEPOINTS || !CONFIG_ANDROID_VENDOR_HOOKS */ +/* suppress trace hooks */ +#define DECLARE_HOOK DECLARE_EVENT_NOP +#define DECLARE_RESTRICTED_HOOK(name, proto, args, cond) \ + DECLARE_EVENT_NOP(name, PARAMS(proto), PARAMS(args)) +#endif From fd0edef76b42f3c969ee9e9d4b6fc35acb13f6eb Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Tue, 5 Jan 2021 12:10:06 +1100 Subject: [PATCH 3/3] BACKPORT: FROMGIT: mm: improve mprotect(R|W) efficiency on pages referenced once In the Scudo memory allocator [1] we would like to be able to detect use-after-free vulnerabilities involving large allocations by issuing mprotect(PROT_NONE) on the memory region used for the allocation when it is deallocated. Later on, after the memory region has been "quarantined" for a sufficient period of time we would like to be able to use it for another allocation by issuing mprotect(PROT_READ|PROT_WRITE). Before this patch, after removing the write protection, any writes to the memory region would result in page faults and entering the copy-on-write code path, even in the usual case where the pages are only referenced by a single PTE, harming performance unnecessarily. Make it so that any pages in anonymous mappings that are only referenced by a single PTE are immediately made writable during the mprotect so that we can avoid the page faults. This program shows the critical syscall sequence that we intend to use in the allocator: #include #include enum { kSize = 131072 }; int main(int argc, char **argv) { char *addr = (char *)mmap(0, kSize, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); for (int i = 0; i != 100000; ++i) { memset(addr, i, kSize); mprotect((void *)addr, kSize, PROT_NONE); mprotect((void *)addr, kSize, PROT_READ | PROT_WRITE); } } The effect of this patch on the above program was measured on a DragonBoard 845c by taking the median real time execution time of 10 runs. Before: 3.19s After: 0.79s The effect was also measured using one of the microbenchmarks that we normally use to benchmark the allocator [2], after modifying it to make the appropriate mprotect calls [3]. With an allocation size of 131072 bytes to trigger the allocator's "large allocation" code path the per-iteration time was measured as follows: Before: 33364ns After: 6886ns This patch means that we do more work during the mprotect call itself in exchange for less work when the pages are accessed. In the worst case, the pages are not accessed at all. The effect of this patch in such cases was measured using the following program: #include #include enum { kSize = 131072 }; int main(int argc, char **argv) { char *addr = (char *)mmap(0, kSize, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); memset(addr, 1, kSize); for (int i = 0; i != 100000; ++i) { #ifdef PAGE_FAULT memset(addr + (i * 4096) % kSize, i, 4096); #endif mprotect((void *)addr, kSize, PROT_NONE); mprotect((void *)addr, kSize, PROT_READ | PROT_WRITE); } } With PAGE_FAULT undefined (0 pages touched after removing write protection) the median real time execution time of 100 runs was measured as follows: Before: 0.325928s After: 0.365493s With PAGE_FAULT defined (1 page touched) the measurements were as follows: Before: 0.441516s After: 0.380251s So it seems that even with a single page fault the new approach is faster. I saw similar results if I adjusted the programs to use a larger mapping size. With kSize = 1048576 I get these numbers with PAGE_FAULT undefined: Before: 1.563078s After: 1.607476s i.e. around 3%. And these with PAGE_FAULT defined: Before: 1.684663s After: 1.683272s i.e. about the same. What I think we may conclude from these results is that for smaller mappings the advantage of the previous approach, although measurable, is wiped out by a single page fault. I think we may expect that there should be at least one access resulting in a page fault (under the previous approach) after making the pages writable, since the program presumably made the pages writable for a reason. For larger mappings we may guesstimate that the new approach wins if the density of future page faults is > 0.4%. But for the mappings that are large enough for density to matter (not just the absolute number of page faults) it doesn't seem like the increase in mprotect latency would be very large relative to the total mprotect execution time. Link: https://lkml.kernel.org/r/20201230004134.1185017-1-pcc@google.com Link: https://linux-review.googlesource.com/id/I98d75ef90e20330c578871c87494d64b1df3f1b8 Link: [1] https://source.android.com/devices/tech/debug/scudo Link: [2] https://cs.android.com/android/platform/superproject/+/master:bionic/benchmarks/stdlib_benchmark.cpp;l=53;drc=e8693e78711e8f45ccd2b610e4dbe0b94d551cc9 Link: [3] https://github.com/pcc/llvm-project/commit/scudo-mprotect-secondary Signed-off-by: Peter Collingbourne [pcc: resolved minor conflict] Cc: Kostya Kortchinsky Signed-off-by: Andrew Morton Signed-off-by: Stephen Rothwell (cherry picked from commit 2a9e75c907fa2de626d77dd4051fc038f0dbaf52 https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git akpm) Bug: 135772972 Change-Id: I98d75ef90e20330c578871c87494d64b1df3f1b8 --- mm/mprotect.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/mprotect.c b/mm/mprotect.c index 65d317058e9e..9b0b9fbcfe06 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -43,6 +43,8 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, spinlock_t *ptl; unsigned long pages = 0; int target_node = NUMA_NO_NODE; + bool anon_writable = + vma_is_anonymous(vma) && (vma->vm_flags & VM_WRITE); /* * Can be called with only the mmap_sem for reading by @@ -119,7 +121,11 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, (pte_soft_dirty(ptent) || !(vma->vm_flags & VM_SOFTDIRTY))) { ptent = pte_mkwrite(ptent); + } else if (anon_writable && + page_mapcount(pte_page(ptent)) == 1) { + ptent = pte_mkwrite(ptent); } + ptep_modify_prot_commit(vma, addr, pte, oldpte, ptent); pages++; } else if (IS_ENABLED(CONFIG_MIGRATION)) {