Commit Graph

1149486 Commits

Author SHA1 Message Date
Sooyong Suk
aee36dd530 ANDROID: mm: add vendor hooks in madvise for swap entry
Add vendor hooks in madvise for swap entry
- android_vh_madvise_pageout_swap_entry
- android_vh_madvise_swapin_walk_pmd_entry
- android_vh_process_madvise_end

Bug: 284059805

Change-Id: Ic389244e343737a583286c20cadb6774efd8890c
Signed-off-by: Sooyong Suk <s.suk@samsung.com>
2023-06-05 23:12:28 +00:00
Peter Collingbourne
c0cfeeaa88 BACKPORT: FROMLIST: arm64: mte: Simplify swap tag restoration logic
As a result of the previous two patches, there are no circumstances
in which a swapped-in page is installed in a page table without first
having arch_swap_restore() called on it. Therefore, we no longer need
the logic in set_pte_at() that restores the tags, so remove it.

Signed-off-by: Peter Collingbourne <pcc@google.com>
Link: https://linux-review.googlesource.com/id/I8ad54476f3b2d0144ccd8ce0c1d7a2963e5ff6f3
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/all/20230523004312.1807357-4-pcc@google.com/
Change-Id: I8ad54476f3b2d0144ccd8ce0c1d7a2963e5ff6f3
[pcc: resolved merge conflict]
Bug: 274890466
2023-06-05 21:53:19 +00:00
Peter Collingbourne
131714e34b FROMLIST: mm: Call arch_swap_restore() from unuse_pte()
We would like to move away from requiring architectures to restore
metadata from swap in the set_pte_at() implementation, as this is not only
error-prone but adds complexity to the arch-specific code. This requires
us to call arch_swap_restore() before calling swap_free() whenever pages
are restored from swap. We are currently doing so everywhere except in
unuse_pte(); do so there as well.

Signed-off-by: Peter Collingbourne <pcc@google.com>
Link: https://linux-review.googlesource.com/id/I68276653e612d64cde271ce1b5a99ae05d6bbc4f
Suggested-by: David Hildenbrand <david@redhat.com>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: "Huang, Ying" <ying.huang@intel.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/all/20230523004312.1807357-3-pcc@google.com/
Change-Id: I68276653e612d64cde271ce1b5a99ae05d6bbc4f
Bug: 274890466
2023-06-05 21:53:19 +00:00
Peter Collingbourne
3805b879f5 FROMLIST: mm: Call arch_swap_restore() from do_swap_page()
Commit c145e0b47c ("mm: streamline COW logic in do_swap_page()") moved
the call to swap_free() before the call to set_pte_at(), which meant that
the MTE tags could end up being freed before set_pte_at() had a chance
to restore them. Fix it by adding a call to the arch_swap_restore() hook
before the call to swap_free().

Signed-off-by: Peter Collingbourne <pcc@google.com>
Link: https://linux-review.googlesource.com/id/I6470efa669e8bd2f841049b8c61020c510678965
Cc: <stable@vger.kernel.org> # 6.1
Fixes: c145e0b47c ("mm: streamline COW logic in do_swap_page()")
Reported-by: Qun-wei Lin (林群崴) <Qun-wei.Lin@mediatek.com>
Closes: https://lore.kernel.org/all/5050805753ac469e8d727c797c2218a9d780d434.camel@mediatek.com/
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: "Huang, Ying" <ying.huang@intel.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/all/20230523004312.1807357-2-pcc@google.com/
Change-Id: I6470efa669e8bd2f841049b8c61020c510678965
Bug: 274890466
2023-06-05 21:53:19 +00:00
Sachin Gupta
098028adf7 ANDROID: abi_gki_aarch64_qcom: Update symbol list
Symbols added:
   sdhci_dumpregs

Bug: 285546222
Change-Id: I18fe46273b13f21e59fd4f556efbe560f581139d
Signed-off-by: Sachin Gupta <quic_sachgupt@quicinc.com>
2023-06-05 20:44:15 +00:00
xiaofeng
71844b8ed9 ANDROID: GKI: Update symbol list for xiaomi
2 function symbol(s) added
  'int __traceiter_android_vh_alloc_pages_reclaim_bypass(gfp_t gfp_mask, int order, int alloc_flags,
	int migratetype, struct page **page)'
  'int __traceiter_android_vh_alloc_pages_failure_bypass(gfp_t gfp_mask, int order, int alloc_flags,
	int migratetype, struct page **page)'

2 variable symbol(s) added
  'struct tracepoint __tracepoint_android_vh_alloc_pages_reclaim_bypass'
  'struct tracepoint __tracepoint_android_vh_alloc_pages_failure_bypass'

Bug: 284059793
Change-Id: I766d37e4f4cea8c3ce6e925e95ab920152eebbb1
Signed-off-by: xiaofeng <xiaofeng5@xiaomi.com>
2023-06-05 16:38:22 +00:00
xiaofeng
025b5a487b ANDROID: vendor_hooks:vendor hook for __alloc_pages_slowpath.
add vendor hook in __alloc_pages_slowpath ahead of
__alloc_pages_direct_reclaim and warn_alloc.

Bug: 243629905
Change-Id: Ieacc6cf79823c0bfacfdeec9afb55ed66f40d0b0
Signed-off-by: xiaofeng <xiaofeng5@xiaomi.com>
2023-06-05 16:38:22 +00:00
Dezhi Huang
60b0f85e24 ANDROID: ABI: Update honor symbol list
3 function symbol(s) added
  'int __traceiter_android_vh_file_is_tiny_bypass(void*, bool, bool*)'
  'int __traceiter_android_vh_modify_scan_control(void*, u64*, unsigned long*, struct mem_cgroup*, bool*, bool*)'
  'int __traceiter_android_vh_should_continue_reclaim(u64*, unsigned long*, unsigned long*, bool*)'

3 variable symbol(s) added
  'struct tracepoint __tracepoint_android_vh_file_is_tiny_bypass'
  'struct tracepoint __tracepoint_android_vh_modify_scan_control'
  'struct tracepoint __tracepoint_android_vh_should_continue_reclaim'

Bug: 279793370
Change-Id: Ieb2a90f1317453b982341f06765bb2625daa645a
Signed-off-by: Dezhi Huang <huangdezhi@hihonor.com>
2023-06-05 16:31:49 +00:00
Dezhi Huang
3e2dc32f59 ANDROID: mm: create vendor hooks for memory reclaim
we try to adjust page reclaim operations based on the running task
and kernel memory pressure. Thus, we want to create some vendor hooks
into kernel6.1.

Firstly, we add ADNRROID_VENDOR_DATA into the struct scan_control,
special operations would be performed based on this special scan option.
We measure the importance of the current process in the system and
obtain its weight, which is recorded in ANDROID_VENDOR_DATA.

The hook function: trace_android_vh_modify_scan_control is added inside
of the function modify_scan_control() to adjust reclaim operations based
on memory pressure.

The hook function: trace_android_vh_should_continue_reclaim is added inside
of the function shrink_node() to decide if page_reclaim would continue
or not based on memory pressure.

The hook function: trace_android_vh_file_is_tiny_bypass is added into the
function prepare_scan_count() to decide if the file pages should be skipped
in condition to file refualts and memory pressure.

Bug: 279793370
Change-Id: I1efe9d3e866f37b0295c7cd94ec8ca0117a9bd4a
Signed-off-by: Dezhi Huang <huangdezhi@hihonor.com>
2023-06-05 16:31:49 +00:00
杨辉
8e6a28c815 UPSTREAM: kcsan: Avoid READ_ONCE() in read_instrumented_memory()
Haibo Li reported:

 | Unable to handle kernel paging request at virtual address
 |   ffffff802a0d8d7171
 | Mem abort info
 |   ESR = 0x9600002121
 |   EC = 0x25: DABT (current EL), IL = 32 bitsts
 |   SET = 0, FnV = 0 0
 |   EA = 0, S1PTW = 0 0
 |   FSC = 0x21: alignment fault
 | Data abort info
 |   ISV = 0, ISS = 0x0000002121
 |   CM = 0, WnR = 0 0
 | swapper pgtable: 4k pages, 39-bit VAs, pgdp=000000002835200000
 | [ffffff802a0d8d71] pgd=180000005fbf9003, p4d=180000005fbf9003,
 | pud=180000005fbf9003, pmd=180000005fbe8003, pte=006800002a0d8707
 | Internal error: Oops: 96000021 [#1] PREEMPT SMP
 | Modules linked in:
 | CPU: 2 PID: 45 Comm: kworker/u8:2 Not tainted
 |   5.15.78-android13-8-g63561175bbda-dirty #1
 | ...
 | pc : kcsan_setup_watchpoint+0x26c/0x6bc
 | lr : kcsan_setup_watchpoint+0x88/0x6bc
 | sp : ffffffc00ab4b7f0
 | x29: ffffffc00ab4b800 x28: ffffff80294fe588 x27: 0000000000000001
 | x26: 0000000000000019 x25: 0000000000000001 x24: ffffff80294fdb80
 | x23: 0000000000000000 x22: ffffffc00a70fb68 x21: ffffff802a0d8d71
 | x20: 0000000000000002 x19: 0000000000000000 x18: ffffffc00a9bd060
 | x17: 0000000000000001 x16: 0000000000000000 x15: ffffffc00a59f000
 | x14: 0000000000000001 x13: 0000000000000000 x12: ffffffc00a70faa0
 | x11: 00000000aaaaaaab x10: 0000000000000054 x9 : ffffffc00839adf8
 | x8 : ffffffc009b4cf00 x7 : 0000000000000000 x6 : 0000000000000007
 | x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffffffc00a70fb70
 | x2 : 0005ff802a0d8d71 x1 : 0000000000000000 x0 : 0000000000000000
 | Call trace:
 |  kcsan_setup_watchpoint+0x26c/0x6bc
 |  __tsan_read2+0x1f0/0x234
 |  inflate_fast+0x498/0x750
 |  zlib_inflate+0x1304/0x2384
 |  __gunzip+0x3a0/0x45c
 |  gunzip+0x20/0x30
 |  unpack_to_rootfs+0x2a8/0x3fc
 |  do_populate_rootfs+0xe8/0x11c
 |  async_run_entry_fn+0x58/0x1bc
 |  process_one_work+0x3ec/0x738
 |  worker_thread+0x4c4/0x838
 |  kthread+0x20c/0x258
 |  ret_from_fork+0x10/0x20
 | Code: b8bfc2a8 2a0803f7 14000007 d503249f (78bfc2a8) )
 | ---[ end trace 613a943cb0a572b6 ]-----

The reason for this is that on certain arm64 configuration since
e35123d83e ("arm64: lto: Strengthen READ_ONCE() to acquire when
CONFIG_LTO=y"), READ_ONCE() may be promoted to a full atomic acquire
instruction which cannot be used on unaligned addresses.

Fix it by avoiding READ_ONCE() in read_instrumented_memory(), and simply
forcing the compiler to do the required access by casting to the
appropriate volatile type. In terms of generated code this currently
only affects architectures that do not use the default READ_ONCE()
implementation.

The only downside is that we are not guaranteed atomicity of the access
itself, although on most architectures a plain load up to machine word
size should still be atomic (a fact the default READ_ONCE() still relies
on itself).

BUG: 285794521
(cherry picked from commit 8dec88070d)
Reported-by: Haibo Li <haibo.li@mediatek.com>
Tested-by: Haibo Li <haibo.li@mediatek.com>
Cc: <stable@vger.kernel.org> # 5.17+
Change-Id: I16c9f83c3b4e28021a936249cafb1501760aa59d
Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: 杨辉 <yanghui10@xiaomi.corp-partner.google.com>
2023-06-05 15:02:47 +00:00
jianzhou
675bc3a00e ANDROID: abi_gki_aarch64_qcom: update symbol list
Symbols added:
   page_pinner_inited
   __page_pinner_put_page
   _trace_android_vh_record_pcpu_rwsem_starttime

Bug: 285243673
Change-Id: I7cf6ca8ff637f3d7de9daba597b09ca27b813e48
Signed-off-by: jianzhou <quic_jianzhou@quicinc.com>
2023-06-05 14:45:20 +00:00
Todd Kjos
7b14897460 ANDROID: Update ABI as part of crash fix
Ok to commit this before KMI update since CRC change only affects the broken
hooks which are only used by the partner that introduced the hooks.

INFO: variable symbol 'struct tracepoint __tracepoint_android_rvh_psci_cpu_suspend' changed
  CRC changed from 0x4628ef5b to 0xf9b81cca

variable symbol 'struct tracepoint __tracepoint_android_rvh_psci_tos_resident_on' changed
  CRC changed from 0x477813d5 to 0xb163a362

Fixes: b7a7fd15ed ("ANDROID: vendor_hooks: psci: add hook to check if cpu is allowed to power off")
Bug: 285477556
Change-Id: I0539ac8ff1d26a6ba8dd0f13fc09b53f5ee0335b
Signed-off-by: Todd Kjos <tkjos@google.com>
2023-06-02 20:46:44 +00:00
Todd Kjos
9e2fa0a396 ANDROID: Fix incorrect hook declaration
Two hooks that need to be restricted were correctly named with "_rvh_"
but were incorrectly declared as normal hooks. This resulted in crashes
for at least 1 partner:

------------[ cut here ]------------
WARNING: CPU: 0 PID: 0 at include/trace/hooks/psci.h:19 psci_0_2_cpu_suspend+0x124/0x1d8
Modules linked in:
CPU: 0 PID: 0 Comm: swapper/0 Tainted: G S      W          6.1.25-android14-7-00072-gf10e53af33a0 #1
Hardware name: Samsung ERD9945 board based on S5E9945 (DT)
pstate: 624003c5 (nZCv DAIF +PAN -UAO +TCO -DIT -SSBS BTYPE=--)
pc : psci_0_2_cpu_suspend+0x124/0x1d8
lr : psci_0_2_cpu_suspend+0x88/0x1d8
sp : ffffffd00b1f7b20
x29: ffffffd00b1f7b30
[0:      swapper/0:    0]  x28: ffffffd00b217be4 x27: 0000000000000001
x26: 0000000000000000 x25: ffffff8915b689fc x24: 93ffff8837750100

x23: 000000008cc8e544 x22: 00000000000000c0
 x21: 0000000000010000
x20: 000000008147a038 x19: efffffc000000000 x18: 0000000000000000

x17: 0000000000000000 x16: 00000000000000ff x15: 0000000000000000
x14: 0000000000000000 x13: ffffffd00b22ae00 x12: ffffffb90a98d000
x11: ffffffd00b1d9850
x10: 0000000100000001 x9 : efffffc000000000
x8 : 0000000100000001
[0:      swapper/0:    0]  x7 : 015001f2b5593519
[0:      swapper/0:    0]  x6 : 0000000000310000
x5 : 0000000000000000
 x4 : 0000000000000000 x3 : 0000000000000000
[0:      swapper/0:    0] x2 : 0000000000000000 x1 : ffffff8915b66850 x0 : 0000000000000000

Call trace:
 psci_0_2_cpu_suspend+0x124/0x1d8
 psci_suspend_finisher+0x2c/0x38
 cpu_suspend+0x8c/0x16c
 psci_cpu_suspend_enter+0x54/0x7c
 psci_enter_idle_state+0x64/0x94
 cpuidle_enter_state+0x1dc/0x9b8
 cpuidle_enter+0x58/0x7c
 call_cpuidle+0x30/0x58
[0:      swapper/0:    0]  do_idle+0x214/0x2b8
 cpu_startup_entry+0x2c/0x30
 kernel_init+0x0/0x180
 start_kernel+0x0/0x444
 start_kernel+0x368/0x444
 __primary_switched+0xc0/0xc8
Kernel panic - not syncing: kernel: panic_on_warn set ...

Fixes: b7a7fd15ed ("ANDROID: vendor_hooks: psci: add hook to check if cpu is allowed to power off")
Bug: 285477556
Change-Id: I44ca332dc61dab025a0e33c94e8ad2f5eaffb6f8
Signed-off-by: Todd Kjos <tkjos@google.com>
2023-06-02 20:46:44 +00:00
Nagireddy Annem
e57fe10b5a ANDROID: abi_gki_aarch64_qcom: Add GIC and hibernation APIs
Add below fnctions and symbols to support GIC Deepsleep
and Hibernation feature.

4 function symbol(s) added
  'int __traceiter_android_vh_gic_v3_suspend(void*, struct gic_chip_data_v3*)'
  'void gic_v3_cpu_init()'
  'void gic_v3_dist_init()'
  'void gic_v3_dist_wait_for_rwp()'

1 variable symbol(s) added
  'struct tracepoint __tracepoint_android_vh_gic_v3_suspend'

Bug: 279879797

Change-Id: I96e439ef537e5dfc4e16c76fe6dd91bd5f13d6dd
Signed-off-by: Nagireddy Annem <quic_nannem@quicinc.com>
Signed-off-by: Darshankumar Jagdishchandra Thakkar <quic_djagdish@quicinc.com>
Signed-off-by: kamasali Satyanarayan <quic_kamasali@quicinc.com>
2023-06-02 17:11:39 +00:00
Maulik Shah
227d23d61d ANDROID: gic-v3: Export gic_v3_resume() for vendor GIC enhancements
syscore ops in gic-v3 takes care of invoking gic_v3_resume() when
exiting from "deep" suspend. However for "s2idle" suspend syscore
ops will not get invoked.

Vendor modules can register for s2idle notifications and
invoke gic_v3_resume() when the first cpu is waking up from s2idle.

Bug: 279879797
Change-Id: Ifd48d676a5bc907eb957c2002934e18bd1c9c095
Signed-off-by: Maulik Shah <mkshah@codeaurora.org>
Signed-off-by: Shreyas K K <quic_shrekk@quicinc.com>
2023-06-02 17:02:43 +00:00
Nagireddy Annem
275c8705e5 ANDROID: irqchip/irq-gic-v3: Add vendor hook for gic suspend
This change adds vendor hook for gic suspend syscore ops callback.
And it is invoked during deepsleep and hibernation to store
gic register snapshot.

Bug: 279879797
Change-Id: I4e3729afa4daf18d73e00ee9601b6da72a578b4a
Signed-off-by: Nagireddy Annem <quic_nannem@quicinc.com>
Signed-off-by: Shreyas K K <quic_shrekk@quicinc.com>
2023-06-02 17:02:43 +00:00
Mao Jinlong
c9539979a9 ANDROID: abi_gki_aarch64_qcom: Update abi_gki_aarch64_qcom for DMA
Add dma_alloc_noncontiguous, dma_free_noncontiguous,
dma_vmap_noncontiguous and dma_vunmap_noncontiguous symbols.

Symbols added:
   dma_alloc_noncontiguous
   dma_free_noncontiguous
   dma_vmap_noncontiguous
   dma_vunmap_noncontiguous

Bug: 284818225
Change-Id: Ifb8238071fbd15b2d27d1cfc33b856ae4c18c3f1
Signed-off-by: Chetan C R <quic_cchinnad@quicinc.com>
Signed-off-by: Mao Jinlong <quic_jinlmao@quicinc.com>
Signed-off-by: Zhenhua Huang <quic_zhenhuah@quicinc.com>
(cherry picked from commit b3bb41cebdeb0688b508df20f0db5f55a87e46e8)
2023-06-02 16:59:18 +00:00
Weichao Guo
6da02f9101 ANDROID: GKI: Update symbols to abi_gki_aarch64_oplus for extend copy & fbarrier feature
8 function symbol(s) added
  'int __blkdev_issue_discard(struct block_device*, sector_t, sector_t, gfp_t, struct bio**)'
  'unsigned long __page_file_index(struct page*)'
  'void address_space_init_once(struct address_space*)'
  'void blk_finish_plug(struct blk_plug*)'
  'void blk_start_plug(struct blk_plug*)'
  'bool prepare_to_wait_exclusive(struct wait_queue_head*, struct wait_queue_entry*, int)'
  'void** radix_tree_lookup_slot(const struct xarray*, unsigned long)'
  'void radix_tree_replace_slot(struct xarray*, void**, void*)'

Bug: 283021230
Change-Id: Iec663ed6ed23c8c3245b609c3d8748919fa34471
Signed-off-by: Weichao Guo <guoweichao@oppo.corp-partner.google.com>
2023-06-01 20:55:23 +00:00
Sarthak Garg
87b384408e ANDROID: abi_gki_aarch64_qcom: Update symbol list
Symbols added:
   dev_pm_opp_remove
   __mmc_claim_host
   mmc_execute_tuning
   mmc_get_card
   mmc_get_ext_csd
   mmc_hs200_tuning
   mmc_issue_type
   __mmc_poll_for_busy
   mmc_prepare_busy_cmd
   mmc_put_card
   mmc_release_host
   mmc_retune_hold
   mmc_retune_release
   mmc_select_bus_width
   mmc_select_card
   mmc_select_hs400
   mmc_select_hs
   mmc_select_hs_ddr
   mmc_select_timing
   mmc_send_status
   mmc_set_bus_mode
   mmc_set_bus_width
   mmc_set_clock
   mmc_set_initial_state
   mmc_set_timing
   mmc_wait_for_cmd
   __traceiter_android_rvh_mmc_resume
   __traceiter_android_rvh_mmc_suspend
   __tracepoint_android_rvh_mmc_resume
   __tracepoint_android_rvh_mmc_suspend

Bug: 283922495
Change-Id: I9d3ff4fbdf6eb5df5798302cbe3409592b4c91c6
Signed-off-by: Sarthak Garg <quic_sartgarg@quicinc.com>
2023-06-01 18:00:57 +00:00
Sarthak Garg
a3a743e67f ANDROID: mmc: core: Export core functions for kernel modules usage
Export core functions for kernel modules usage.

Bug: 283922495
Link:
https://patchwork.kernel.org/project/linux-mmc/patch/20230401165723.19762-3-quic_sartgarg@quicinc.com/

Change-Id: Ia7904a5da3207e6f39590e092a7805e5260cd752
Signed-off-by: Sarthak Garg <quic_sartgarg@quicinc.com>
2023-06-01 18:00:57 +00:00
Sarthak Garg
631a2db5a3 ANDROID: vendor_hooks: Define new hooks in _mmc_suspend/resume
Define new hooks in _mmc_suspend/resume to control few things in card
suspend/resume paths which further allows to enable some additional
steps in mmc_suspend/resume paths as per host specific requirements.

Bug: 283922495
Link:
https://patchwork.kernel.org/project/linux-mmc/patch/20230401165723.19762-2-quic_sartgarg@quicinc.com/

Change-Id: Ief52d1dc6b01e9866f004b46687dffa4eb1e7bc1
Signed-off-by: Sarthak Garg <quic_sartgarg@quicinc.com>
2023-06-01 18:00:57 +00:00
Cixi Geng
e82e89e170 ANDROID: update symbol for unisoc vendor_hooks
Add the psci_cpu_suspend and psci_tos_resident_on.

2 function symbol(s) added
  'int __traceiter_android_rvh_psci_cpu_suspend(void*, u32, bool*)'
  'int __traceiter_android_rvh_psci_tos_resident_on(void*, int, bool*)'

2 variable symbol(s) added
  'struct tracepoint __tracepoint_android_rvh_psci_cpu_suspend'
  'struct tracepoint __tracepoint_android_rvh_psci_tos_resident_on'

Bug: 284797902
Change-Id: Ie4e740757631fe6dc194bf83873a64df34769193
Signed-off-by: Cixi Geng <cixi.geng1@unisoc.com>
2023-06-01 09:20:41 +08:00
Jian Gong
b7a7fd15ed ANDROID: vendor_hooks: psci: add hook to check if cpu is allowed to power off
While TOS is running alongside with linux, cpu power off operation by linux
may need be denied by TOS in some scenarios.
This patch added two hooks in psci_tos_resident_on and psci_cpu_suspend
to hook cpu off operation.

The function psci_tos_resident_on originally is used to check if TOS is resident on
a specific cpu and that cpu is dedicated for running TOS exclusively. If so, that
cpu can not be power off. Actually if TOS supports SMP, TOS may need deny any
other cpu to power down in some cases, i.e. there are no-expired timers in TOS.
Thus the first hook for psci_tos_resident_on is used to determine if
the specific cpu is allowed to power off in the cpu hotplug path.

Besides cpu hotplug, a cpu also can power off by cpu_suspend.
The second hook for psci_cpu_suspend determines if cpu suspend should go through
or not. When the same conditions described above meets, cpu suspend will break up.

The hook cherry-pick from commit 88d88955ae0b8b1f1a555d7810beb6c8ca4ca0f1
and changed vh to rvh according to commit 949edf7539b60058cf2da98f24db2b6d4d89eaa0

Bug: 284797902
Change-Id: Ib329beeff20f0cfef263f6a7813280d33f6a5eaa
Signed-off-by: Jian Gong <Jian.Gong@unisoc.com>
Signed-off-by: Cixi Geng <cixi.geng1@unisoc.com>
2023-06-01 09:18:28 +08:00
Xuewen Yan
3be7d118e7 ANDROID: Add vendor hook to the effective_cpu_util
android_rvh_effective_cpu_util:
	To perform vendor-specific cpu util, it is used in EAS/schedutil/thermal.

The effective_cpu_util would be called when thermal calc the dynamic power,
it's non-atomic context, so set the hook be restricted.

Bug: 226686099
Test: build pass

Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
Change-Id: I6fd77f44ca4328f5ef37d96989aa2e08d65e29bb
2023-06-01 00:39:32 +00:00
Chun-Hung Wu
0c2142745d ANDROID: Update symbol list for mtk
5 function symbol(s) added
  'void _trace_android_vh_record_pcpu_rwsem_starttime(struct task_struct*, unsigned long)'
  'struct file* filp_open_block(const char*, int, umode_t)'
  'int iommu_dev_disable_feature(struct device*, enum iommu_dev_features)'
  'int of_pci_get_max_link_speed(struct device_node*)'
  'void sched_clock_register(u64(*)(), int, unsigned long)'

Bug: 284836453
Change-Id: If41140f2f203664c58aeb9ce49498436a26113be
Signed-off-by: Chun-Hung Wu <chun-hung.wu@mediatek.com>
2023-05-31 23:11:43 +00:00
YOUNGJIN JOO
6f7dc871a6 ANDROID: ABI: update symbol list for galaxy
5 function symbol(s) added
  'void __kfree_skb(struct sk_buff*)'
  'int __traceiter_android_vh_ptype_head(void*, const struct packet_type*, struct list_head*)'
  'int __traceiter_kfree_skb(void*, struct sk_buff*, void*, enum skb_drop_reason)'
  'int skb_copy_ubufs(struct sk_buff*, gfp_t)'
  'struct usb_device* usb_alloc_dev(struct usb_device*, struct usb_bus*, unsigned int)'

2 variable symbol(s) added
  'struct tracepoint __tracepoint_android_vh_ptype_head'
  'struct tracepoint __tracepoint_kfree_skb'

Bug: 284426833
Change-Id: If9dd8836500afd45ed49838f00ccca7effbdb54f
Signed-off-by: YOUNGJIN JOO <youngjin79.joo@samsung.com>
2023-05-31 23:11:08 +00:00
Di Shen
b0a752c3aa ANDROID: update symbol for unisoc vendor_hooks
Add some thermal related symbols.

6 function symbol(s) added
  'int __traceiter_android_vh_get_thermal_zone_device(void*, struct thermal_zone_device*)'
  'int __traceiter_android_vh_modify_thermal_request_freq(void*, struct cpufreq_policy*, unsigned long*)'
  'int __traceiter_android_vh_modify_thermal_target_freq(void*, struct cpufreq_policy*, unsigned int*)'
  'int __traceiter_android_vh_thermal_power_cap(void*, u32*)'
  'int __traceiter_android_vh_thermal_register(void*, struct cpufreq_policy*)'
  'int __traceiter_android_vh_thermal_unregister(void*, struct cpufreq_policy*)'

6 variable symbol(s) added
  'struct tracepoint __tracepoint_android_vh_get_thermal_zone_device'
  'struct tracepoint __tracepoint_android_vh_modify_thermal_request_freq'
  'struct tracepoint __tracepoint_android_vh_modify_thermal_target_freq'
  'struct tracepoint __tracepoint_android_vh_thermal_power_cap'
  'struct tracepoint __tracepoint_android_vh_thermal_register'
  'struct tracepoint __tracepoint_android_vh_thermal_unregister'

Bug: 285078223

Signed-off-by: Di Shen <di.shen@unisoc.com>
Change-Id: I5c9e07c4754f24b70c6bb12333aec10b4db5b03f
2023-05-31 21:08:10 +00:00
Jeson Gao
ce7ceff8c8 ANDROID: thermal: Add vendor hook to check power range
For SoC's skin temperature, we have to use more stringent temperature
control to make IPA can monitor and mitigate temperature control earlier
and faster, so add it to meet platform thermal requirement.

Bug: 211564753

Signed-off-by: Jeson Gao <jeson.gao@unisoc.com>
Signed-off-by: Di Shen <di.shen@unisoc.com>
Change-Id: Iaef87287eef93d6fdbc3c58c93f70c1525e38296
(cherry picked from commit 6709f52325)
(cherry picked from commit 97a290b0e5)
2023-05-31 21:08:10 +00:00
Di Shen
7191b6a759 ANDROID: thermal: Add vendor hook to get thermal zone device
Need to get temperature data and config info from thermal zone device.

Bug: 208946028

Signed-off-by: Di Shen <di.shen@unisoc.com>
Signed-off-by: Jeson Gao <jeson.gao@unisoc.com>
Change-Id: I5945df5258181b4a441b6bbe09327099491418b3
(cherry picked from commit c53f0e3530)
(cherry picked from commit 12b8ef18b2)
2023-05-31 21:08:10 +00:00
Jeson Gao
1fe511720a ANDROID: thermal: Add hook for cpufreq thermal
Add hook to get cpufreq policy data after registering and unregistering
cpufreq thermal for platform thermal requirement.

Bug: 228423762

Signed-off-by: Jeson Gao <jeson.gao@unisoc.com>
Signed-off-by: Di Shen <di.shen@unisoc.com>
Change-Id: I9c6bc88f348f252c428560427bd8bca91092edfa
(cherry picked from commit fbe6f8708d)
2023-05-31 21:08:10 +00:00
Zhenhua Huang
78fe8913d1 UPSTREAM: mm,kfence: decouple kfence from page granularity mapping judgement
Kfence only needs its pool to be mapped as page granularity, if it is
inited early. Previous judgement was a bit over protected. From [1], Mark
suggested to "just map the KFENCE region a page granularity". So I
decouple it from judgement and do page granularity mapping for kfence
pool only. Need to be noticed that late init of kfence pool still requires
page granularity mapping.

Page granularity mapping in theory cost more(2M per 1GB) memory on arm64
platform. Like what I've tested on QEMU(emulated 1GB RAM) with
gki_defconfig, also turning off rodata protection:
Before:
[root@liebao ]# cat /proc/meminfo
MemTotal:         999484 kB
After:
[root@liebao ]# cat /proc/meminfo
MemTotal:        1001480 kB

To implement this, also relocate the kfence pool allocation before the
linear mapping setting up, arm64_kfence_alloc_pool is to allocate phys
addr, __kfence_pool is to be set after linear mapping set up.

LINK: [1] https://lore.kernel.org/linux-arm-kernel/Y+IsdrvDNILA59UN@FVFF77S0Q05N/
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Zhenhua Huang <quic_zhenhuah@quicinc.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: Marco Elver <elver@google.com>
Link: https://lore.kernel.org/r/1679066974-690-1-git-send-email-quic_zhenhuah@quicinc.com
Signed-off-by: Will Deacon <will@kernel.org>

BUG: 284812202
Change-Id: I8e7c565d3f4d6349a028a6a060259d62cf5beee7
(cherry picked from commit bfa7965b33)
Signed-off-by: Zhenhua Huang <quic_zhenhuah@quicinc.com>
2023-05-31 17:22:42 +00:00
Tetsuo Handa
8035e57ec7 UPSTREAM: mm/page_alloc: fix potential deadlock on zonelist_update_seq seqlock
commit 1007843a91 upstream.

syzbot is reporting circular locking dependency which involves
zonelist_update_seq seqlock [1], for this lock is checked by memory
allocation requests which do not need to be retried.

One deadlock scenario is kmalloc(GFP_ATOMIC) from an interrupt handler.

  CPU0
  ----
  __build_all_zonelists() {
    write_seqlock(&zonelist_update_seq); // makes zonelist_update_seq.seqcount odd
    // e.g. timer interrupt handler runs at this moment
      some_timer_func() {
        kmalloc(GFP_ATOMIC) {
          __alloc_pages_slowpath() {
            read_seqbegin(&zonelist_update_seq) {
              // spins forever because zonelist_update_seq.seqcount is odd
            }
          }
        }
      }
    // e.g. timer interrupt handler finishes
    write_sequnlock(&zonelist_update_seq); // makes zonelist_update_seq.seqcount even
  }

This deadlock scenario can be easily eliminated by not calling
read_seqbegin(&zonelist_update_seq) from !__GFP_DIRECT_RECLAIM allocation
requests, for retry is applicable to only __GFP_DIRECT_RECLAIM allocation
requests.  But Michal Hocko does not know whether we should go with this
approach.

Another deadlock scenario which syzbot is reporting is a race between
kmalloc(GFP_ATOMIC) from tty_insert_flip_string_and_push_buffer() with
port->lock held and printk() from __build_all_zonelists() with
zonelist_update_seq held.

  CPU0                                   CPU1
  ----                                   ----
  pty_write() {
    tty_insert_flip_string_and_push_buffer() {
                                         __build_all_zonelists() {
                                           write_seqlock(&zonelist_update_seq);
                                           build_zonelists() {
                                             printk() {
                                               vprintk() {
                                                 vprintk_default() {
                                                   vprintk_emit() {
                                                     console_unlock() {
                                                       console_flush_all() {
                                                         console_emit_next_record() {
                                                           con->write() = serial8250_console_write() {
      spin_lock_irqsave(&port->lock, flags);
      tty_insert_flip_string() {
        tty_insert_flip_string_fixed_flag() {
          __tty_buffer_request_room() {
            tty_buffer_alloc() {
              kmalloc(GFP_ATOMIC | __GFP_NOWARN) {
                __alloc_pages_slowpath() {
                  zonelist_iter_begin() {
                    read_seqbegin(&zonelist_update_seq); // spins forever because zonelist_update_seq.seqcount is odd
                                                             spin_lock_irqsave(&port->lock, flags); // spins forever because port->lock is held
                    }
                  }
                }
              }
            }
          }
        }
      }
      spin_unlock_irqrestore(&port->lock, flags);
                                                             // message is printed to console
                                                             spin_unlock_irqrestore(&port->lock, flags);
                                                           }
                                                         }
                                                       }
                                                     }
                                                   }
                                                 }
                                               }
                                             }
                                           }
                                           write_sequnlock(&zonelist_update_seq);
                                         }
    }
  }

This deadlock scenario can be eliminated by

  preventing interrupt context from calling kmalloc(GFP_ATOMIC)

and

  preventing printk() from calling console_flush_all()

while zonelist_update_seq.seqcount is odd.

Since Petr Mladek thinks that __build_all_zonelists() can become a
candidate for deferring printk() [2], let's address this problem by

  disabling local interrupts in order to avoid kmalloc(GFP_ATOMIC)

and

  disabling synchronous printk() in order to avoid console_flush_all()

.

As a side effect of minimizing duration of zonelist_update_seq.seqcount
being odd by disabling synchronous printk(), latency at
read_seqbegin(&zonelist_update_seq) for both !__GFP_DIRECT_RECLAIM and
__GFP_DIRECT_RECLAIM allocation requests will be reduced.  Although, from
lockdep perspective, not calling read_seqbegin(&zonelist_update_seq) (i.e.
do not record unnecessary locking dependency) from interrupt context is
still preferable, even if we don't allow calling kmalloc(GFP_ATOMIC)
inside
write_seqlock(&zonelist_update_seq)/write_sequnlock(&zonelist_update_seq)
section...

Link: https://lkml.kernel.org/r/8796b95c-3da3-5885-fddd-6ef55f30e4d3@I-love.SAKURA.ne.jp
Fixes: 3d36424b3b ("mm/page_alloc: fix race condition between build_all_zonelists and page allocation")
Link: https://lkml.kernel.org/r/ZCrs+1cDqPWTDFNM@alley [2]
Reported-by: syzbot <syzbot+223c7461c58c58a4cb10@syzkaller.appspotmail.com>
  Link: https://syzkaller.appspot.com/bug?extid=223c7461c58c58a4cb10 [1]
Change-Id: Ifc0c6ed9be6d36166367811ad412bedc66ed713e
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Cc: Petr Mladek <pmladek@suse.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: John Ogness <john.ogness@linutronix.de>
Cc: Patrick Daly <quic_pdaly@quicinc.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit b528537d13)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-05-31 16:27:26 +00:00
Mel Gorman
fa3ef799ad UPSTREAM: mm: page_alloc: skip regions with hugetlbfs pages when allocating 1G pages
commit 4d73ba5fa7 upstream.

A bug was reported by Yuanxi Liu where allocating 1G pages at runtime is
taking an excessive amount of time for large amounts of memory.  Further
testing allocating huge pages that the cost is linear i.e.  if allocating
1G pages in batches of 10 then the time to allocate nr_hugepages from
10->20->30->etc increases linearly even though 10 pages are allocated at
each step.  Profiles indicated that much of the time is spent checking the
validity within already existing huge pages and then attempting a
migration that fails after isolating the range, draining pages and a whole
lot of other useless work.

Commit eb14d4eefd ("mm,page_alloc: drop unnecessary checks from
pfn_range_valid_contig") removed two checks, one which ignored huge pages
for contiguous allocations as huge pages can sometimes migrate.  While
there may be value on migrating a 2M page to satisfy a 1G allocation, it's
potentially expensive if the 1G allocation fails and it's pointless to try
moving a 1G page for a new 1G allocation or scan the tail pages for valid
PFNs.

Reintroduce the PageHuge check and assume any contiguous region with
hugetlbfs pages is unsuitable for a new 1G allocation.

The hpagealloc test allocates huge pages in batches and reports the
average latency per page over time.  This test happens just after boot
when fragmentation is not an issue.  Units are in milliseconds.

hpagealloc
                               6.3.0-rc6              6.3.0-rc6              6.3.0-rc6
                                 vanilla   hugeallocrevert-v1r1   hugeallocsimple-v1r2
Min       Latency       26.42 (   0.00%)        5.07 (  80.82%)       18.94 (  28.30%)
1st-qrtle Latency      356.61 (   0.00%)        5.34 (  98.50%)       19.85 (  94.43%)
2nd-qrtle Latency      697.26 (   0.00%)        5.47 (  99.22%)       20.44 (  97.07%)
3rd-qrtle Latency      972.94 (   0.00%)        5.50 (  99.43%)       20.81 (  97.86%)
Max-1     Latency       26.42 (   0.00%)        5.07 (  80.82%)       18.94 (  28.30%)
Max-5     Latency       82.14 (   0.00%)        5.11 (  93.78%)       19.31 (  76.49%)
Max-10    Latency      150.54 (   0.00%)        5.20 (  96.55%)       19.43 (  87.09%)
Max-90    Latency     1164.45 (   0.00%)        5.53 (  99.52%)       20.97 (  98.20%)
Max-95    Latency     1223.06 (   0.00%)        5.55 (  99.55%)       21.06 (  98.28%)
Max-99    Latency     1278.67 (   0.00%)        5.57 (  99.56%)       22.56 (  98.24%)
Max       Latency     1310.90 (   0.00%)        8.06 (  99.39%)       26.62 (  97.97%)
Amean     Latency      678.36 (   0.00%)        5.44 *  99.20%*       20.44 *  96.99%*

                   6.3.0-rc6   6.3.0-rc6   6.3.0-rc6
                     vanilla   revert-v1   hugeallocfix-v2
Duration User           0.28        0.27        0.30
Duration System       808.66       17.77       35.99
Duration Elapsed      830.87       18.08       36.33

The vanilla kernel is poor, taking up to 1.3 second to allocate a huge
page and almost 10 minutes in total to run the test.  Reverting the
problematic commit reduces it to 8ms at worst and the patch takes 26ms.
This patch fixes the main issue with skipping huge pages but leaves the
page_count() out because a page with an elevated count potentially can
migrate.

BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=217022
Link: https://lkml.kernel.org/r/20230414141429.pwgieuwluxwez3rj@techsingularity.net
Fixes: eb14d4eefd ("mm,page_alloc: drop unnecessary checks from pfn_range_valid_contig")
Change-Id: I552f0631f15e41038219e207c994fa7702b269fa
Signed-off-by: Mel Gorman <mgorman@techsingularity.net>
Reported-by: Yuanxi Liu <y.liu@naruida.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: David Hildenbrand <david@redhat.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 059f24aff6)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-05-31 16:27:26 +00:00
Uttkarsh Aggarwal
c0462c4b11 UPSTREAM: usb: gadget: f_fs: Add unbind event before functionfs_unbind
While exercising the unbind path, with the current implementation
the functionfs_unbind would be calling which waits for the ffs->mutex
to be available, however within the same time ffs_ep0_read is invoked
& if no setup packets are pending, it will invoke function
wait_event_interruptible_exclusive_locked_irq which by definition waits
for the ev.count to be increased inside the same mutex for which
functionfs_unbind is waiting.
This creates deadlock situation because the functionfs_unbind won't
get the lock until ev.count is increased which can only happen if
the caller ffs_func_unbind can proceed further.

Following is the illustration:

	CPU1				CPU2

ffs_func_unbind()		ffs_ep0_read()
				mutex_lock(ffs->mutex)
				wait_event(ffs->ev.count)
functionfs_unbind()
  mutex_lock(ffs->mutex)
  mutex_unlock(ffs->mutex)

ffs_event_add()

<deadlock>

Fix this by moving the event unbind before functionfs_unbind
to ensure the ev.count is incrased properly.

Fixes: 6a19da1110 ("usb: gadget: f_fs: Prevent race during ffs_ep0_queue_wait")
Cc: stable <stable@kernel.org>
Signed-off-by: Uttkarsh Aggarwal <quic_uaggarwa@quicinc.com>
Link: https://lore.kernel.org/r/20230525092854.7992-1-quic_uaggarwa@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Bug: 285072336
(cherry picked from commit efb6b53520)

Change-Id: I1a001606f62f1966825d47809cd1c887e3d6fb71
Signed-off-by: Uttkarsh Aggarwal <quic_uaggarwa@quicinc.com>
2023-05-31 16:16:30 +00:00
Alexander Potapenko
f800df6e1f UPSTREAM: mm: kmsan: handle alloc failures in kmsan_vmap_pages_range_noflush()
commit 47ebd0310e upstream.

As reported by Dipanjan Das, when KMSAN is used together with kernel fault
injection (or, generally, even without the latter), calls to kcalloc() or
__vmap_pages_range_noflush() may fail, leaving the metadata mappings for
the virtual mapping in an inconsistent state.  When these metadata
mappings are accessed later, the kernel crashes.

To address the problem, we return a non-zero error code from
kmsan_vmap_pages_range_noflush() in the case of any allocation/mapping
failure inside it, and make vmap_pages_range_noflush() return an error if
KMSAN fails to allocate the metadata.

This patch also removes KMSAN_WARN_ON() from vmap_pages_range_noflush(),
as these allocation failures are not fatal anymore.

Link: https://lkml.kernel.org/r/20230413131223.4135168-1-glider@google.com
Fixes: b073d7f8ae ("mm: kmsan: maintain KMSAN metadata for page operations")
Change-Id: I2a50da1c7cc438a30026b2b18d425fff2ea349b6
Signed-off-by: Alexander Potapenko <glider@google.com>
Reported-by: Dipanjan Das <mail.dipanjan.das@gmail.com>
  Link: https://lore.kernel.org/linux-mm/CANX2M5ZRrRA64k0hOif02TjmY9kbbO2aCBPyq79es34RXZ=cAw@mail.gmail.com/
Reviewed-by: Marco Elver <elver@google.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit bd6f3421a5)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-05-31 15:20:12 +00:00
xieliujie
e03c7f09c6 ANDROID: ABI: Update oplus symbol list
1 function symbol(s) added
  'int __traceiter_android_vh_sync_txn_recvd(void*, struct task_struct*, struct task_struct*)'

1 variable symbol(s) added
  'struct tracepoint __tracepoint_android_vh_sync_txn_recvd'

Bug: 283132152
Change-Id: Ic03bf3872011bd213106d804d7cf31d71bbaf81d
Signed-off-by: xieliujie <xieliujie@oppo.com>
2023-05-30 22:58:11 +00:00
Avichal Rakesh
cdcdf1d9af Revert "FROMGIT: usb: gadget: udc: core: Prevent redundant calls to pullup"
This reverts commit b9bb33b73c.

Reason: This patch breaks any USB gadget function that deactivates the
gadget on bind (by setting bind_deactivated = true).

Bug: 285019584

Change-Id: I2885819dd75e9d65de8258b7d2f6fc5d98de6c68
Signed-off-by: Avichal Rakesh <arakesh@google.com>
2023-05-30 22:22:38 +00:00
xieliujie
44d674262f ANDROID: GKI: Update symbols to symbol list
3 function symbol(s) added
  'int __traceiter_android_vh_binder_del_ref(void*, task_struct*, uint32_t)'
  'int __traceiter_android_vh_binder_new_ref(void*, task_struct*, uint32_t, int)'
  'int __traceiter_android_vh_binder_proc_transaction(void*, task_struct*, task_struct*, task_struct*, int, unsigned int, bool)'

3 variable symbol(s) added
  'struct tracepoint __tracepoint_android_vh_binder_del_ref'
  'struct tracepoint __tracepoint_android_vh_binder_new_ref'
  'struct tracepoint __tracepoint_android_vh_binder_proc_transaction'

Bug: 283132152
Change-Id: Ie02a5f234e7f7ce2be313d3770d574151eccfc99
Signed-off-by: xieliujie <xieliujie@oppo.com>
2023-05-30 21:51:17 +00:00
zhengding chen
4952744d12 ANDROID: vendor_hooks: Add hooks for binder proc transaction
When servicemanager process added service proxy from other process
register the service, we want to know the matching relation between
handle in the process and service name. When binder transaction
happened, We want to know what process calls what method on what service.

Bug: 186604985
Signed-off-by: zhengding chen <chenzhengding@oppo.com>
Change-Id: I813d1cde10294d8665f899f7fef0d444ec1f1f5e
2023-05-30 21:51:17 +00:00
Alexander Potapenko
843caf6daa UPSTREAM: mm: kmsan: handle alloc failures in kmsan_ioremap_page_range()
commit fdea03e12a upstream.

Similarly to kmsan_vmap_pages_range_noflush(), kmsan_ioremap_page_range()
must also properly handle allocation/mapping failures.  In the case of
such, it must clean up the already created metadata mappings and return an
error code, so that the error can be propagated to ioremap_page_range().
Without doing so, KMSAN may silently fail to bring the metadata for the
page range into a consistent state, which will result in user-visible
crashes when trying to access them.

Link: https://lkml.kernel.org/r/20230413131223.4135168-2-glider@google.com
Fixes: b073d7f8ae ("mm: kmsan: maintain KMSAN metadata for page operations")
Change-Id: Iae12299853f5f39b473c509d0ad63ac20d0425e7
Signed-off-by: Alexander Potapenko <glider@google.com>
Reported-by: Dipanjan Das <mail.dipanjan.das@gmail.com>
  Link: https://lore.kernel.org/linux-mm/CANX2M5ZRrRA64k0hOif02TjmY9kbbO2aCBPyq79es34RXZ=cAw@mail.gmail.com/
Reviewed-by: Marco Elver <elver@google.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 433a7ecaed)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-05-30 17:15:55 +00:00
Naoya Horiguchi
ac51e1f090 UPSTREAM: mm/huge_memory.c: warn with pr_warn_ratelimited instead of VM_WARN_ON_ONCE_FOLIO
commit 4737edbbdd upstream.

split_huge_page_to_list() WARNs when called for huge zero pages, which
sounds to me too harsh because it does not imply a kernel bug, but just
notifies the event to admins.  On the other hand, this is considered as
critical by syzkaller and makes its testing less efficient, which seems to
me harmful.

So replace the VM_WARN_ON_ONCE_FOLIO with pr_warn_ratelimited.

Link: https://lkml.kernel.org/r/20230406082004.2185420-1-naoya.horiguchi@linux.dev
Fixes: 478d134e95 ("mm/huge_memory: do not overkill when splitting huge_zero_page")
Change-Id: Ib41a08bf87cc55ce240a63eddf5609aa7c8976ef
Signed-off-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
Reported-by: syzbot+07a218429c8d19b1fb25@syzkaller.appspotmail.com
  Link: https://lore.kernel.org/lkml/000000000000a6f34a05e6efcd01@google.com/
Reviewed-by: Yang Shi <shy828301@gmail.com>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: Xu Yu <xuyu@linux.alibaba.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit e8a7bdb6f7)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-05-30 17:15:55 +00:00
David Hildenbrand
12132bd611 UPSTREAM: mm/userfaultfd: fix uffd-wp handling for THP migration entries
commit 24bf08c437 upstream.

Looks like what we fixed for hugetlb in commit 44f86392bd ("mm/hugetlb:
fix uffd-wp handling for migration entries in
hugetlb_change_protection()") similarly applies to THP.

Setting/clearing uffd-wp on THP migration entries is not implemented
properly.  Further, while removing migration PMDs considers the uffd-wp
bit, inserting migration PMDs does not consider the uffd-wp bit.

We have to set/clear independently of the migration entry type in
change_huge_pmd() and properly copy the uffd-wp bit in
set_pmd_migration_entry().

Verified using a simple reproducer that triggers migration of a THP, that
the set_pmd_migration_entry() no longer loses the uffd-wp bit.

Link: https://lkml.kernel.org/r/20230405160236.587705-2-david@redhat.com
Fixes: f45ec5ff16 ("userfaultfd: wp: support swap and page migration")
Change-Id: I263a9fd8a6695f546fe5c5279a439f4f1c151c48
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Cc: <stable@vger.kernel.org>
Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit cc647e05db)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-05-30 17:15:55 +00:00
Peter Xu
ab721b09b1 UPSTREAM: mm/khugepaged: check again on anon uffd-wp during isolation
commit dd47ac428c upstream.

Khugepaged collapse an anonymous thp in two rounds of scans.  The 2nd
round done in __collapse_huge_page_isolate() after
hpage_collapse_scan_pmd(), during which all the locks will be released
temporarily.  It means the pgtable can change during this phase before 2nd
round starts.

It's logically possible some ptes got wr-protected during this phase, and
we can errornously collapse a thp without noticing some ptes are
wr-protected by userfault.  e1e267c792 wanted to avoid it but it only
did that for the 1st phase, not the 2nd phase.

Since __collapse_huge_page_isolate() happens after a round of small page
swapins, we don't need to worry on any !present ptes - if it existed
khugepaged will already bail out.  So we only need to check present ptes
with uffd-wp bit set there.

This is something I found only but never had a reproducer, I thought it
was one caused a bug in Muhammad's recent pagemap new ioctl work, but it
turns out it's not the cause of that but an userspace bug.  However this
seems to still be a real bug even with a very small race window, still
worth to have it fixed and copy stable.

Link: https://lkml.kernel.org/r/20230405155120.3608140-1-peterx@redhat.com
Fixes: e1e267c792 ("khugepaged: skip collapse if uffd-wp detected")
Change-Id: Iab7f0ac5b9b6d055485ca244b2fa1e13f0dbc570
Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Yang Shi <shy828301@gmail.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Cc: Nadav Amit <nadav.amit@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 519dbe737f)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-05-30 14:32:04 +00:00
Jiachen Zhang
c0f5b9920f UPSTREAM: fuse: always revalidate rename target dentry
commit ccc031e26a upstream.

The previous commit df8629af29 ("fuse: always revalidate if exclusive
create") ensures that the dentries are revalidated on O_EXCL creates.  This
commit complements it by also performing revalidation for rename target
dentries.  Otherwise, a rename target file that only exists in kernel
dentry cache but not in the filesystem will result in EEXIST if
RENAME_NOREPLACE flag is used.

Change-Id: I3500c168b37469e0fcf5664a3deb4d54e45b926d
Signed-off-by: Jiachen Zhang <zhangjiachen.jaycee@bytedance.com>
Signed-off-by: Zhang Tianci <zhangtianci.1997@bytedance.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Yang Bo <yb203166@antfin.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 7ca973d830)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-05-30 14:31:59 +00:00
wangshuai12
1464eaee1b ANDROID: GKI: update xiaomi symbol list
ABI DIFFERENCES HAVE BEEN DETECTED!
12 function symbol(s) added
  'u64 __blkg_prfill_rwstat(struct seq_file*, struct blkg_policy_data*, const struct blkg_rwstat_sample*)'
  'u64 __blkg_prfill_u64(struct seq_file*, struct blkg_policy_data*, u64)'
  'const char* bdi_dev_name(struct backing_dev_info*)'
  'void blkcg_print_blkgs(struct seq_file*, struct blkcg*, u64(*)(struct seq_file*, struct blkg_policy_data*, int), const struct blkcg_policy*, int, bool)'
  'void blkg_conf_finish(struct blkg_conf_ctx*)'
  'int blkg_conf_prep(struct blkcg*, const struct blkcg_policy*, char*, struct blkg_conf_ctx*)'
  'u64 blkg_prfill_rwstat(struct seq_file*, struct blkg_policy_data*, int)'
  'void blkg_rwstat_exit(struct blkg_rwstat*)'
  'int blkg_rwstat_init(struct blkg_rwstat*, gfp_t)'
  'void blkg_rwstat_recursive_sum(struct blkcg_gq*, struct blkcg_policy*, int, struct blkg_rwstat_sample*)'
  'struct io_cq* ioc_lookup_icq(struct request_queue*)'
  'void percpu_counter_add_batch(struct percpu_counter*, s64, s32)'

1 variable symbol(s) added
  'struct static_key_true io_cgrp_subsys_on_dfl_key'

Bug: 284828333

Change-Id: I7536f25b8d22a25518b8a3426b6b069689054dcf
Signed-off-by: wangshuai12 <wangshuai12@xiaomi.corp-partner.google.com>
2023-05-29 17:28:25 +00:00
Kalesh Singh
500484f5be BACKPORT: FROMGIT: Multi-gen LRU: fix workingset accounting
On Android app cycle workloads, MGLRU showed a significant reduction in
workingset refaults although pgpgin/pswpin remained relatively unchanged.
This indicated MGLRU may be undercounting workingset refaults.

This has impact on userspace programs, like Android's LMKD, that monitor
workingset refault statistics to detect thrashing.

It was found that refaults were only accounted if the MGLRU shadow entry
was for a recently evicted folio.  However, recently evicted folios should
be accounted as workingset activation, and refaults should be accounted
regardless of recency.

Fix MGLRU's workingset refault and activation accounting to more closely
match that of the conventional active/inactive LRU.

Link: https://lkml.kernel.org/r/20230523205922.3852731-1-kaleshsingh@google.com
Fixes: ac35a49023 ("mm: multi-gen LRU: minimal implementation")
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
Reported-by: Charan Teja Kalla <quic_charante@quicinc.com>
Acked-by: Yu Zhao <yuzhao@google.com>
Cc: Brian Geffon <bgeffon@google.com>
Cc: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
Cc: Oleksandr Natalenko <oleksandr@natalenko.name>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 02ad728453d2ddb09d7ce5e59854ebb27544d488 https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-unstable)
Bug: 284043217
[ Kalesh Singh - Fix conflicts in mm/workingset.c ]
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
Change-Id: I6d42cca9064e66099fbbc20aa2143961f84b2003
2023-05-27 00:38:36 +00:00
Ajay Agarwal
80d7019423 BACKPORT: FROMGIT: PCI: dwc: Wait for link up only if link is started
In dw_pcie_host_init() regardless of whether the link has been
started or not, the code waits for the link to come up. Even in
cases where start_link() is not defined the code ends up spinning
in a loop for 1 second. Since in some systems dw_pcie_host_init()
gets called during probe, this one second loop for each pcie
interface instance ends up extending the boot time.

Wait for the link up in only if the start_link() is defined.

Bug: 270085637
Link: https://lore.kernel.org/r/20230412093425.3659088-1-ajayagarwal@google.com
Tested-by: Will McVicker <willmcvicker@google.com>
Signed-off-by: Sajid Dalvi <sdalvi@google.com>
Signed-off-by: Ajay Agarwal <ajayagarwal@google.com>
Signed-off-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
(cherry picked from commit da56a1bfba
 https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git controller/dwc)
[willmcvicker: fixed trivial merge conflicts]
Signed-off-by: Will McVicker <willmcvicker@google.com>
Change-Id: Ia4d9b41b2a15cb077025f6250d8fa07c495a17a9
2023-05-26 23:16:15 +00:00
SEO HOYOUNG
4439750641 ANDROID: ABI: update symbol list for exynos
2 function symbol(s) added
  'int __traceiter_android_vh_ufs_mcq_abort(void*, struct ufs_hba*, struct scsi_cmnd*, int*)'
  'int __traceiter_android_vh_ufs_use_mcq_hooks(void*, struct ufs_hba*, bool*)'

Bug: 280041543
Change-Id: Ibd3413dd89db1a0e68d98102fc27d0a852051593
Signed-off-by: SEO HOYOUNG <hy50.seo@samsung.com>
2023-05-26 18:14:14 +00:00
SEO HOYOUNG
e5b77cd49a ANDROID: ufs: Improve MCQ err handling
- Add android vendor hook:
 android_vh_ufs_mcq_abort
 android_vh_ufs_use_mcq_hooks

Bug: 280041543
Change-Id: I9cd4372c20fc179804e26391e2cb758fb02e5b72
Signed-off-by: SEO HOYOUNG <hy50.seo@samsung.com>
2023-05-26 18:14:14 +00:00
xieliujie
0dec547282 ANDROID: ABI: Update oplus symbol list
1 function symbol(s) added
  'int __traceiter_android_rvh_post_init_entity_util_avg(void*, struct sched_entity*)'

1 variable symbol(s) added
  'struct tracepoint __tracepoint_android_rvh_post_init_entity_util_avg'

Bug: 283132152
Change-Id: I0a98c23c0582312cbb375b2d598662b9611e4cd2
Signed-off-by: xieliujie <xieliujie@oppo.com>
2023-05-26 17:58:14 +08:00