Commit Graph

1149385 Commits

Author SHA1 Message Date
Alice Chao
7ce023f185 FROMGIT: scsi: ufs: core: mcq: Fix &hwq->cq_lock deadlock issue
When ufshcd_err_handler() is executed, CQ event interrupt can enter waiting
for the same lock. This can happen in ufshcd_handle_mcq_cq_events() and
also in ufs_mtk_mcq_intr(). The following warning message will be generated
when &hwq->cq_lock is used in IRQ context with IRQ enabled. Use
ufshcd_mcq_poll_cqe_lock() with spin_lock_irqsave instead of spin_lock to
resolve the deadlock issue.

[name:lockdep&]WARNING: inconsistent lock state
[name:lockdep&]--------------------------------
[name:lockdep&]inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage.
[name:lockdep&]kworker/u16:4/260 [HC0[0]:SC0[0]:HE1:SE1] takes:
  ffffff8028444600 (&hwq->cq_lock){?.-.}-{2:2}, at:
ufshcd_mcq_poll_cqe_lock+0x30/0xe0
[name:lockdep&]{IN-HARDIRQ-W} state was registered at:
  lock_acquire+0x17c/0x33c
  _raw_spin_lock+0x5c/0x7c
  ufshcd_mcq_poll_cqe_lock+0x30/0xe0
  ufs_mtk_mcq_intr+0x60/0x1bc [ufs_mediatek_mod]
  __handle_irq_event_percpu+0x140/0x3ec
  handle_irq_event+0x50/0xd8
  handle_fasteoi_irq+0x148/0x2b0
  generic_handle_domain_irq+0x4c/0x6c
  gic_handle_irq+0x58/0x134
  call_on_irq_stack+0x40/0x74
  do_interrupt_handler+0x84/0xe4
  el1_interrupt+0x3c/0x78
<snip>

Possible unsafe locking scenario:
       CPU0
       ----
  lock(&hwq->cq_lock);
  <Interrupt>
    lock(&hwq->cq_lock);
  *** DEADLOCK ***
2 locks held by kworker/u16:4/260:

[name:lockdep&]
 stack backtrace:
CPU: 7 PID: 260 Comm: kworker/u16:4 Tainted: G S      W  OE
6.1.17-mainline-android14-2-g277223301adb #1
Workqueue: ufs_eh_wq_0 ufshcd_err_handler

 Call trace:
  dump_backtrace+0x10c/0x160
  show_stack+0x20/0x30
  dump_stack_lvl+0x98/0xd8
  dump_stack+0x20/0x60
  print_usage_bug+0x584/0x76c
  mark_lock_irq+0x488/0x510
  mark_lock+0x1ec/0x25c
  __lock_acquire+0x4d8/0xffc
  lock_acquire+0x17c/0x33c
  _raw_spin_lock+0x5c/0x7c
  ufshcd_mcq_poll_cqe_lock+0x30/0xe0
  ufshcd_poll+0x68/0x1b0
  ufshcd_transfer_req_compl+0x9c/0xc8
  ufshcd_err_handler+0x3bc/0xea0
  process_one_work+0x2f4/0x7e8
  worker_thread+0x234/0x450
  kthread+0x110/0x134
  ret_from_fork+0x10/0x20

Bug: 267974767
(cherry picked from commit 948afc6961
 https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git 6.4/scsi-staging)
Fixes: ed975065c3 ("scsi: ufs: core: mcq: Add completion support in poll")
Reviewed-by: Can Guo <quic_cang@quicinc.com>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Alice Chao <alice.chao@mediatek.com>
Link: https://lore.kernel.org/r/20230424080400.8955-1-alice.chao@mediatek.com
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

Change-Id: Ib75c41579138a14e820eba19b876cd4ae786dd67
Signed-off-by: Alice Chao <alice.chao@mediatek.com>
2023-05-18 21:32:33 +00:00
xieliujie
bae70267ba ANDROID: ABI: Update oplus symbol list
1 variable symbol(s) added
  'struct update_util_data* cpufreq_update_util_data'

Bug: 283132152
Change-Id: Icc09071a8d19608dd16a629980722dc958f54385
Signed-off-by: xieliujie <xieliujie@oppo.com>
2023-05-18 20:39:10 +00:00
Liujie Xie
2878003246 ANDROID: android: Export symbols for invoking cpufreq_update_util()
In order to update cpufreq, vendor modules invoke cpufreq_update_util(),
but when we build our modules, report error:
ERROR: modpost: "cpufreq_update_util_data" [xxx.ko] undefined!

Bug: 192218676
Signed-off-by: Liujie Xie <xieliujie@oppo.com>
Change-Id: Ib1da70229f04b08d8d812d065021dec0bf891e0e
(cherry picked from commit 8943a2e7a3)
(cherry picked from commit d1bc61dd85e8d28f1df0e22e2d73aa9e99cb645e)
2023-05-18 20:39:10 +00:00
xieliujie
546b0f9d8b ANDROID: ABI: Update oplus symbol list
1 function symbol(s) added
  'int __traceiter_task_rename(void*, struct task_struct*, const char*)'

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

Bug: 283132152
Change-Id: Idbb6e338e0959b3cd2f5f4cc2f1e1ff17e4a9b72
Signed-off-by: xieliujie <xieliujie@oppo.com>
2023-05-18 20:38:34 +00:00
Liujie Xie
e3e91e9f2a ANDROID: vendor_hooks: Export the tracepoints task_rename
Export the tracepoint task_rename to identify specific new task,
to customize task's util for power and performance, or optimize
task schedule parameters.

Bug: 189985971

Change-Id: I3bb71eae316e3096d361e7b47012ba46ea4be509
Signed-off-by: Liujie Xie <xieliujie@oppo.com>
(cherry picked from commit 016d3f7b69)
(cherry picked from commit cfc14a391adb4d44d8186694b4884815bd85be6c)
2023-05-18 20:38:34 +00:00
Veerendranath Jakkam
42b899d573 ANDROID: Add macros to create reserved data fields to backport upstream changes
Adds various macros to create reserved data fields in kernel data
structures before the freeze and to use reserved data fields to backport
upstream changes after the freeze.

Bug: 233387627
Change-Id: Ifbf8444861fa805593ce9b4837cd2653b7b7a0b0
Signed-off-by: Veerendranath Jakkam <quic_vjakkam@quicinc.com>
2023-05-18 18:16:11 +00:00
Minchan Kim
718da042d1 ANDROID: retry page allocation from buddy on lock contention
spin_trylock may fail due to a parallel drain in rmqueue_pcplist.
In the case, it should retry to allocate with buddy.
It matches with upstream policy.

Fixes: 433445e9a1 ("ANDROID: mm: add cma pcp list")
Change-Id: I07367888d7ede38e09f9d882fc2485baa175fe64
Signed-off-by: Minchan Kim <minchan@google.com>
2023-05-18 17:41:28 +00:00
Dan Carpenter
0ef5d2caad UPSTREAM: KVM: arm64: Fix buffer overflow in kvm_arm_set_fw_reg()
commit a25bc8486f upstream.

The KVM_REG_SIZE() comes from the ioctl and it can be a power of two
between 0-32768 but if it is more than sizeof(long) this will corrupt
memory.

Fixes: 99adb56763 ("KVM: arm/arm64: Add save/restore support for firmware workaround state")
Change-Id: I37107d3a62db584e9d026d5ecaf7d0cc15a4b716
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/4efbab8c-640f-43b2-8ac6-6d68e08280fe@kili.mountain
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 8d6a870a42)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-05-18 16:17:42 +00:00
Quentin Perret
270a77dd07 ANDROID: arm64: Check FGT cap before touching HFGWTR_EL2
Writing to HFGWTR_EL2 is undefined on CPUs without the capability,
so make sure not to touch the register when that is the case.

Bug: 282917063
Bug: 282993310
Change-Id: I85211105d6b1fbee854b4f13f037b8573c5a211c
Signed-off-by: Quentin Perret <qperret@google.com>
2023-05-18 09:10:22 +00:00
Quentin Perret
95cd5f8f94 Revert "ANDROID: Partially Revert "ANDROID: KVM: arm64: Allow tweaking HFGWTR_EL2 from modules""
This reverts commit 6cf9fb4579. It was a
temporary workaround which will be replaced a proper fix shortly.

Bug: 282917063
Bug: 282993310
Change-Id: I0caec4a63aabaecbf3fa7ec5d5b4c6930ea6efcd
Signed-off-by: Quentin Perret <qperret@google.com>
2023-05-18 09:10:22 +00:00
Jaegeuk Kim
630b104caa FROMGIT: f2fs: fix the wrong condition to determine atomic context
Should use !in_task for irq context.

Bug: 281085599
Cc: stable@vger.kernel.org
Fixes: 1aa161e431 ("f2fs: fix scheduling while atomic in decompression path")
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
(cherry picked from commit f063fa43995667dbdf5b46406774a0ad58310dae
 https://git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git dev)
Change-Id: I5ce9286cc380309ee5e294f54ec357a4bfa47d6f
2023-05-18 02:41:06 +00:00
Dezhi Huang
cab47c81b5 ANDROID: GKI: update symbol list file for honor
Create the symbol list file for Honor Device Co.

Bug: 279793369
Signed-off-by: Dezhi Huang <huangdezhi@hihonor.com>
Change-Id: I11bca937366428bc87a174a64b7d6843e3d92339
2023-05-17 21:26:09 +00:00
Zhipeng Wang
3368eaf934 ANDROID: ABI: Update symbol list for imx
3 function symbol(s) added
  'int clocksource_mmio_init(void*, const char*, unsigned long, int, unsigned int, u64(*)(struct clocksource*))'
  'u64 clocksource_mmio_readl_up(struct clocksource*)'
  'int timer_of_init(struct device_node*, struct timer_of*)'

Bug: 283014063

Change-Id: I8c35bfd05da64d2c00c444c6bc0a53a30a12e91c
Signed-off-by: Zhipeng Wang <zhipeng.wang_1@nxp.com>
2023-05-17 21:15:03 +00:00
Charan Teja Kalla
a26891749b ANDROID: mm: shmem: initialize the vendor data
Vendor data is not initialized which can make the drivers to see the
junk. Initialize it.

Bug: 273448633
Fixes: a033dd393f ("ANDROID: mm: shmem: add vendor data in 'shmem_inode_info'")
Change-Id: I44379c97831324e8dd439a27c6326706eb0bcadf
Signed-off-by: Charan Teja Kalla <quic_charante@quicinc.com>
2023-05-17 17:54:56 +00:00
Giuliano Procida
112bf65cbc ANDROID: GKI: refresh STG ABI to new version
prebuilts/kernel-build-tools/linux-x86/bin/stg \
  --stg common/android/abi_gki_aarch64.stg \
  --output common/android/abi_gki_aarch64.stg

Bug: 274744378
Change-Id: I186d187a0272a5bce9015ab0b407830ca2f077db
Signed-off-by: Giuliano Procida <gprocida@google.com>
2023-05-17 12:50:40 +01:00
Jiewen Wang
22406c7dbb ANDROID: GKI: Add symbols to symbol list for vivo
INFO: 2 function symbol(s) added
  'int __traceiter_android_vh_mmap_region(void*, struct vm_area_struct*, unsigned long)'
  'int __traceiter_android_vh_try_to_unmap_one(void*, struct folio*, struct vm_area_struct*, unsigned long, void*, bool)'

2 variable symbol(s) added
  'struct tracepoint __tracepoint_android_vh_mmap_region'
  'struct tracepoint __tracepoint_android_vh_try_to_unmap_one'

Bug: 198385827
Change-Id: Iaf77526f33e865c8f48c47fae14a1e3eb5b3e1a5
Signed-off-by: Jiewen Wang <jiewen.wang@vivo.com>
2023-05-17 12:48:51 +01:00
xieliujie
eb9264dd96 ANDROID: ABI: Update oplus symbol list
2 function symbol(s) added
  'int __traceiter_android_vh_account_process_tick_gran(void*, int, int*)'
  'int __traceiter_android_vh_account_task_time(void*, struct task_struct*, struct rq*, int, int)'

2 variable symbol(s) added
  'struct tracepoint __tracepoint_android_vh_account_process_tick_gran'
  'struct tracepoint __tracepoint_android_vh_account_task_time'

Bug: 279549765
Change-Id: I7f56e7d19352acab04be659bb63a8ad6e42fbeb9
Signed-off-by: xieliujie <xieliujie@oppo.com>
2023-05-17 11:31:51 +00:00
Liujie Xie
c92b19e8e4 ANDROID: vendor_hooks: Add hooks for account process tick
Add a hook in account_process_tick, which help us to get information
about the high load task and the cpu they running on.

Bug: 183260319
Change-Id: I54162ce3c65bd69e08d2d4747e4d4883efe4c442
Signed-off-by: Liujie Xie <xieliujie@oppo.com>
2023-05-17 11:31:51 +00:00
Liujie Xie
32ff609a32 ANDROID: ABI: Update oplus symbol list
1 function symbol(s) added
  'int __traceiter_android_vh_account_process_tick_gran(void*, int, int*)'

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

Bug: 279549765
Change-Id: Ibdb9638b6e225c8326a255b2c3b141498c625942
Signed-off-by: Liujie Xie <xieliujie@oppo.com>
2023-05-17 11:31:51 +00:00
Liujie Xie
ec8c8f6e33 ANDROID: vendor_hooks: add hook account_process_tick_gran
this hook will allow to account tick in every third of more ticks
to save cpu time for accounting

Bug: 279549765
Change-Id: I5d18e0167fdce076d13aecc653dcf6387bcb25f2
Signed-off-by: Liujie Xie <xieliujie@oppo.com>
2023-05-17 11:31:51 +00:00
Jiewen Wang
1a40d683e8 ANDROID: vendor_hooks: Add hook in try_to_unmap_one()
Add hook in try_to_unmap_one() to trace this function for debug memory
swap bugs.

Bug: 198385827
Change-Id: I1fdbe60e09bb491b949e06a07133710453ecca03
Signed-off-by: Jiewen Wang <jiewen.wang@vivo.com>
(cherry picked from commit 5a70133febf92e1269f98b533ce9f188c2e3b135)
2023-05-17 10:04:17 +00:00
Jiewen Wang
190af40844 ANDROID: vendor_hooks: Add hook in mmap_region()
Add hook in mmap_region() to record the vma and address information
of monitored processes.

Bug: 198385827
Change-Id: I0bde29113b47ca7f4a9f5d42a54188e791ca3b7e
Signed-off-by: Jiewen Wang <jiewen.wang@vivo.com>
(cherry picked from commit 73c9d4a9d575107b90a6d9f415fa56f963264d06)
2023-05-17 10:04:17 +00:00
Will McVicker
1b160e2a0e ANDROID: Partially Revert "ANDROID: KVM: arm64: Allow tweaking HFGWTR_EL2 from modules"
This is a partial revert of commit 444b34b83a in order to fix booting
this kernel on devices that don't support FEAT_FGT due to direct
accesses of HFGWTR_EL2 being UNDEFINED. We are retaining the KMI part of
the commit until the next KMI breakage window.

Bug: 282917063
Change-Id: I6c156ef40a5584dc41e4d9d09c80736e30348802
Signed-off-by: Will McVicker <willmcvicker@google.com>
2023-05-17 07:59:36 +00:00
wang qiankun
7d346b229c ANDROID: GKI: update the ABI symbol list
INFO: ABI DIFFERENCES HAVE BEEN DETECTED!
INFO: 1 function symbol(s) added
  'int __traceiter_android_rvh_refrigerator(void*, bool)'

2 variable symbol(s) added
  'struct tracepoint __tracepoint_android_rvh_refrigerator'
  'struct cgroup_subsys freezer_cgrp_subsys'

Bug: 281920779

Change-Id: I58d1bfba887b7f0b6af471e8b18fab368b119b7d
Signed-off-by: wang qiankun <wangqiankun3@xiaomi.corp-partner.google.com>
2023-05-17 00:25:38 +00:00
heshuai1
a9a44851ec ANDROID: freezer: Add vendor hook to freezer for GKI purpose.
Add the vendor hook to freezer.c so that OEM's logic can be executed
when the process is about to be frozen. We need to clear the flag for
some tasks and rebind task dependencies for optimization purposes.

Bug: 187458531
Bug: 281920779

Signed-off-by: heshuai1 <heshuai1@xiaomi.com>
Change-Id: Iea42fd9604d6b33ccd6502425416f0dd28eecebb
(cherry picked from commit a1580311c3)
2023-05-17 00:25:38 +00:00
Zhuguangqing
632ec01905 ANDROID: freezer: export the freezer_cgrp_subsys for GKI purpose.
Exporting the symbol freezer_cgrp_subsys, in that vendor module can
add can_attach & cancel_attach member function. It is vendor-specific
tuning.

Bug: 182496370
Bug: 281920779

Signed-off-by: Zhuguangqing <zhuguangqing@xiaomi.com>
Change-Id: I153682b9d1015eed3f048b45ea6495ebb8f3c261
(cherry picked from commit ee3f4d2821)
(cherry picked from commit 8a90e4d4e555dd5484213c6fec5061958016a194)
2023-05-17 00:25:38 +00:00
wang qiankun
fdd7d6fbac ANDROID: GKI: update the ABI symbol list
INFO: ABI DIFFERENCES HAVE BEEN DETECTED!
INFO: 4 function symbol(s) added
  'int __traceiter_android_vh_binder_alloc_new_buf_locked(void*, size_t, size_t*, int)'
  'int __traceiter_android_vh_binder_reply(void*, struct binder_proc*, struct binder_proc*, struct binder_thread*, struct binder_transaction_data*)'
  'int __traceiter_android_vh_binder_trans(void*, struct binder_proc*, struct binder_proc*, struct binder_thread*, struct binder_transaction_data*)'
  'int __traceiter_android_vh_do_send_sig_info(void*, int, struct task_struct*, struct task_struct*)'

4 variable symbol(s) added
  'struct tracepoint __tracepoint_android_vh_binder_alloc_new_buf_locked'
  'struct tracepoint __tracepoint_android_vh_binder_reply'
  'struct tracepoint __tracepoint_android_vh_binder_trans'
  'struct tracepoint __tracepoint_android_vh_do_send_sig_info'

function symbol 'int snd_usb_power_domain_set(struct snd_usb_audio*, struct snd_usb_power_domain*, unsigned char)' changed
  CRC changed from 0xf4ff4ee5 to 0xb29e40d5

Bug: 281920779

Change-Id: I3e6cd71847ee2eeee26fc8aef985055c00504d14
Signed-off-by: wang qiankun <wangqiankun3@xiaomi.corp-partner.google.com>
2023-05-16 21:47:18 +00:00
Zhuguangqing
17fff41db8 ANDROID: Add vendor hooks for binder perf tuning
Add some hooks in the binder module so that we can do task dependency analysis and statistical work in OEM's module for further optimization.

Bug: 235925535
Bug: 281920779

Signed-off-by: Zhuguangqing <zhuguangqing@xiaomi.com>
Change-Id: Id47e59c4e3ccd07b26eef758ada147b98cd1964e
Signed-off-by: heshuai1 <heshuai1@xiaomi.com>
Signed-off-by: Carlos Llamas <cmllamas@google.com>
[ cmllamas: don't export complete private definition struct binder_alloc
  in vendor hooks, instead just pass member alloc->free_async_space as
  implemented by heshuai1 and squashed here ]
(cherry picked from commit 254fb1f4034fde523378ee58a501d212a59047b7)
2023-05-16 21:44:18 +00:00
Zhuguangqing
bf4922727c ANDROID: Add vendor hooks to signal.
This hook will allow us to get signal messages so that we can set
limitations for certain tasks and restore them when receiving important signals.

Bug: 184898838
Bug: 281920779

Signed-off-by: Zhuguangqing <zhuguangqing@xiaomi.com>
Change-Id: I83a28b0a6eb413976f4c57f2314d008ad792fa0d
(cherry picked from commit 58e3f869fc)
2023-05-16 21:44:18 +00:00
Minchan Kim
27dfd1c13e ANDROID: Update the ABI symbol list
1 function symbol(s) added
  'void __page_pinner_put_page(struct page*)'

1 variable symbol(s) added
  'struct static_key_false page_pinner_inited'
Bug: 274967172
Change-Id: I458edf7089b44696fa270be0ed538441c99ab5e6
Signed-off-by: Minchan Kim <minchan@google.com>
2023-05-16 21:34:27 +00:00
Minchan Kim
2488e2e472 ANDROID: page_pinner: add missing page_pinner_put_page
aosp/2369528 missed page_pinner_put_page in put_page_testzero
path. Fix it.

Bug: 274967172
Change-Id: Ia2af2ffb752f8405b4289ca88cde09f201548e1f
Signed-off-by: Minchan Kim <minchan@google.com>
2023-05-16 21:34:27 +00:00
Charan Teja Kalla
d47c9481da ANDROID: page_pinner: prevent pp_buffer uninitialized access
There is a race window between page_pinner_inited set and the pp_buffer
initialization which cause accessing the pp_buffer->lock. Avoid this by
moving the pp_buffer initialization to page_ext_ops->init() which sets
the page_pinner_inited only after the pp_buffer is initialized.

Race scenario:
1) init_page_pinner is called --> page_pinner_inited is set.

2) __alloc_contig_migrate_range --> __page_pinner_failure_detect()
accesses the pp_buffer->lock(yet to be initialized).

3) Then the pp_buffer is allocated and initialized.

Below is the issue call stack:
 spin_bug+0x0
 _raw_spin_lock_irqsave+0x3c
 __page_pinner_failure_detect+0x110
 __alloc_contig_migrate_range+0x1c4
 alloc_contig_range+0x130
 cma_alloc+0x170
 dma_alloc_contiguous+0xa0
 __dma_direct_alloc_pages+0x16c
 dma_direct_alloc+0x88

Bug: 259024332
Change-Id: I6849ac4d944498b9a431b47cad7adc7903c9bbaa
Signed-off-by: Charan Teja Kalla <quic_charante@quicinc.com>
2023-05-16 21:34:27 +00:00
Suren Baghdasaryan
83b784c3d7 ANDROID: page_pinner: prevent pp_buffer access before initialization
If page_pinner is configured with page_pinner_enabled=false and
failure_tracking=true, pp_buffer will be accessed without being
initialized. Prevent this by adding page_pinner_inited checks in
functions that access it.

Fixes: 898cfbf094a2 ("ANDROID: mm: introduce page_pinner")
Bug: 259024332
Bug: 260179017
Change-Id: I8f612cae3e74d36e8a4eee5edec25281246cbe5e
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Richard Chang <richardycc@google.com>
(cherry picked from commit 23fb3111f63e5fe239a769668275c20493a5849c)
2023-05-16 21:34:27 +00:00
Charan Teja Kalla
231a4cccec ANDROID: mm: fix use-after free of page_ext in page_pinner
Apply new page_ext refcounting scheme to page_pinner.

Bug: 236222283
Bug: 240196534
[surenb: extracted from aosp/2369529]
Change-Id: I3b64caf5a7e8ff316507cc3933f5b3696142268d
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2023-05-16 21:34:27 +00:00
Minchan Kim
e6e6e1273d ANDROID: mm: introduce page_pinner
For CMA allocation, it's really critical to migrate a page but
sometimes it fails. One of the reasons is some driver holds a
page refcount for a long time so VM couldn't migrate the page
at that time.

The concern here is there is no way to find the who hold the
refcount of the page effectively. This patch introduces feature
to keep tracking page's pinner. All get_page sites are vulnerable
to pin a page for a long time but the cost to keep track it would
be significat since get_page is the most frequent kernel operation.
Furthermore, the page could be not user page but kernel page which
is not related to the page migration failure.

Thus, this patch keeps tracks of only migration failed pages to
reduce runtime cost. Once page migration fails in CMA allocation
path, those pages are marked as "migration failure" and every
put_page operation against those pages, callstack of the put
are recorded into page_pinner buffer. Later, admin can see
what pages were failed and who released the refcount since the
failure. It really helps effectively to find out longtime refcount
holder to prevent the page migration.

note: page_pinner doesn't guarantee attributing/unattributing are
atomic if they happen at the same time. It's just best effort so
false-positive could happen.

Bug: 183414571
BUg: 240196534
Signed-off-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Minchan Kim <minchan@google.com>
Change-Id: I603d0c0122734c377db6b1eb95848a6f734173a0
(cherry picked from commit 898cfbf094a2fc13c67fab5b5d3c916f0139833a)
2023-05-16 21:34:27 +00:00
Elliot Berman
4c868837fa ANDROID: abi_gki_aarch64_qcom: Add gh_rm_register_platform_ops
From commit 80dfafb2b9b6 ("ANDROID: gunyah: Sync with latest "firmware:
qcom_scm: Register Gunyah platform ops""), the QCOM platform extensions
now use gh_rm_(un)register_platform_ops instead of the devm_ equivalent
because the platform extensions are no longer directly backed by a
device.

 2 function symbol(s) added
  'int gh_rm_register_platform_ops(struct gh_rm_platform_ops*)'
  'void gh_rm_unregister_platform_ops(struct gh_rm_platform_ops*)'

Bug: 279506910
Change-Id: I7ad36387a9d254691ecf9b769e058d972bd41c42
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
9a9fc8d1b2 ANDROID: gunyah: Sync remaining gunyah drivers with latest
Apply remaining minor fixups from Gunyah v13 patches:

https://lore.kernel.org/all/20230509204801.2824351-1-quic_eberman@quicinc.com/

Bug: 279506910
Change-Id: I1a596b9df29d210c51b612845e4a1aafbea00441
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
afaf163329 ANDROID: gunyah: Sync with latest "mailbox: Add Gunyah message queue mailbox"
Align msgq mailbox implementation to version 13 of Gunyah patches:

https://lore.kernel.org/all/20230509204801.2824351-6-quic_eberman@quicinc.com/

Bug: 279506910
Change-Id: I017873310e6c8650afa3e6dae379c7e7048b7197
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
016d92266e ANDROID: gunyah: Sync with latest "gunyah: Common types and error codes for Gunyah hypercalls"
Rename gh_remap_error to gh_error_remap to align with Gunyah v13
patches:

https://lore.kernel.org/all/20230509204801.2824351-3-quic_eberman@quicinc.com/

Bug: 279506910
Change-Id: Id3e033108a6a42868dc12a9c20c1a06775418979
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
58a642ea08 ANDROID: gunyah: Sync with latest hypercalls
Align hypercalls to Gunyah v13 patches:

https://lore.kernel.org/all/20230509204801.2824351-1-quic_eberman@quicinc.com/

Bug: 279506910
Change-Id: Ie99913e7d9213e4805a98aa04a06c751ece32488
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
a30bae5a9a ANDROID: gunyah: Sync with latest documentation and UAPI
Align docs and UAPI to Gunyah v13 patches:

https://lore.kernel.org/all/20230509204801.2824351-1-quic_eberman@quicinc.com/

Bug: 279506910
Change-Id: I2719f07f69877374ffa88020fe2a23a70d79bb8b
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
b3f59a9b33 ANDROID: gunyah: Sync with latest "firmware: qcom_scm: Register Gunyah platform ops"
The QCOM platform hooks are not enabled in gki_defconfig, but backport
to align to Gunyah v13 patches posted to kernel.org:

https://lore.kernel.org/all/20230509204801.2824351-15-quic_eberman@quicinc.com/

Bug: 279506910
Change-Id: Idce927cfa89cfea137b96024dd3c5a2bf297da82
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
15a4929f8e BACKPORT: firmware: qcom_scm: Use fixed width src vm bitmap
The maximum VMID for assign_mem is 63. Use a u64 to represent this
bitmap instead of architecture-dependent "unsigned int" which varies in
size on 32-bit and 64-bit platforms.

Acked-by: Kalle Valo <kvalo@kernel.org> (ath10k)
Tested-by: Gokul krishna Krishnakumar <quic_gokukris@quicinc.com>
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Reviewed-by: Bjorn Andersson <andersson@kernel.org>
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
Link: https://lore.kernel.org/r/20230213181832.3489174-1-quic_eberman@quicinc.com

Bug: 279506910
(cherry picked from commit 968a26a07f)
Change-Id: Ie7125d1299e4edda47f3e6e9031dc515cfdd8f0f
[eberman: Drop modifications to drivers/remoteproc/qcom_q6v5_pas.c which
don't exist in 14-6.1]
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
b0426ab62e BACKPORT: misc: fastrpc: Pass bitfield into qcom_scm_assign_mem
The srcvm parameter of qcom_scm_assign_mem is a pointer to a bitfield of
VMIDs. The  bitfield is updated with which VMIDs have permissions
after the qcom_scm_assign_mem call. This makes it simpler for clients to
make qcom_scm_assign_mem calls later, they always pass in same srcvm
bitfield and do not need to closely track whether memory was originally
shared.

When restoring permissions to HLOS, fastrpc is incorrectly using the
first VMID directly -- neither the BIT nor the other possible VMIDs the
memory was already assigned to.  We already have a field intended for
this purpose: "perms" in the struct fastrpc_channel_ctx, but it was
never used. Start using the perms field.

Cc: Abel Vesa <abel.vesa@linaro.org>
Cc: Vamsi Krishna Gattupalli <quic_vgattupa@quicinc.com>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Fixes: e90d911906 ("misc: fastrpc: Add support to secure memory map")
Fixes: 0871561055 ("misc: fastrpc: Add support for audiopd")
Fixes: 532ad70c6d ("misc: fastrpc: Add mmap request assigning for static PD pool")
Tested-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>

drivers/misc/fastrpc.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Link: https://lore.kernel.org/r/20230112182313.521467-1-quic_eberman@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Bug: 279506910
(cherry picked from commit aaca766c77)
[eberman: Drop modifications to qcom_scm_assign_mem not in 14-6.1]
Change-Id: I9eff564504fa277519245a446eb6fcad41a0ee42
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
2220f8190a ANDROID: gunyah: Sync with latest "virt: gunyah: Add ioeventfd"
Align ioeventfd handling to Gunyah v13 patches:

https://lore.kernel.org/all/20230509204801.2824351-24-quic_eberman@quicinc.com/

Bug: 279506910
Change-Id: I8d66d83bee284eacb4bc9d76d3cbfd52785d9661
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
1b9d0e44a7 ANDROID: gunyah: Sync with latest "gunyah: vm_mgr: Add ioctls to support basic non-proxy VM boot"
Align VM lifecycle to Gunyah v13 patches posted to kernel.org.

- Move gh_vm_free and kref functions down.
- Simplify/clean up gh_vm_free
- Defer vmid allocation to when the VM is being started

https://lore.kernel.org/all/20230509204801.2824351-12-quic_eberman@quicinc.com/

Bug: 279506910
Change-Id: I413865c16a730365edc83385bc37394b99517ab1
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
28ecb1162a ANDROID: gunyah: Sync with latest "gunyah: vm_mgr: Add/remove user memory regions"
Align Gunyah memory parcel to Gunyah v12 patches posted to kernel.org.

We deviate from a perfect copy from kernel.org because:
 - in pages_are_mergeable, zone_device_pages_have_same_pgmap is not
   present in 6.1. Drop this check.

https://lore.kernel.org/all/20230509204801.2824351-11-quic_eberman@quicinc.com/

Bug: 279506910
Change-Id: I90ec2ac416b24bcc65635f27cae7665ce879783f
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
084d70e264 ANDROID: gunyah: Sync with latest "virt: gunyah: Add resource tickets"
Align resource tickets with the Gunyah v13 pathces posted to kernel.org:

https://lore.kernel.org/all/20230509204801.2824351-19-quic_eberman@quicinc.com/

Bug: 279506910
Change-Id: Ie08544786045b338c332b3a35c125fcb9a77b697
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
5e0785329a ANDROID: gunyah: Sync with latest "gunyah: vm_mgr: Add framework for VM Functions"
Align Gunyah VM Functions with Gunyah v13 patches:

https://lore.kernel.org/all/20230509204801.2824351-18-quic_eberman@quicinc.com/

Bug: 279506910
Change-Id: Id8e043191539d41e4b54cb579ba2a84db76e0f70
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
fea63fe1f1 ANDROID: gunyah: Sync with latest "gunyah: rsc_mgr: Add resource manager RPC core"
Align resource manager and rpc to v12 of Gunyah patches posted to
kernel.org.

 - Rename "buff" to "buf"
 - printk adjustments
 - Comments
 - Stylistic tweaks

https://lore.kernel.org/all/20230509204801.2824351-7-quic_eberman@quicinc.com/

Bug: 279506910
Change-Id: Iff216a9cb3afeb9de75f0b42bf58f139da2ca4bd
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00