Commit Graph

1149379 Commits

Author SHA1 Message Date
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
Elliot Berman
6889a3fbe4 ANDROID: gunyah: Sync with latest "virt: gunyah: Translate gh_rm_hyp_resource into gunyah_resource"
Align the Gunyah IRQ domain to the v13 series:

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

Bug: 279506910
Change-Id: I6807139aa917d89b44cb3d77aa3c790433746f3d
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Elliot Berman
96ddb92d5c ANDROID: gunyah: Sync with latest "virt: gunyah: Add hypercalls to identify Gunyah"
Align arch_is_gh_guest to version 13 of Gunyah patches:

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

Bug: 279506910
Change-Id: I7b4ff1974a1175efb94dfdb1f414771d887ecb1f
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Kees Cook
467d3baa5d BACKPORT: overflow: Introduce overflows_type() and castable_to_type()
Implement a robust overflows_type() macro to test if a variable or
constant value would overflow another variable or type. This can be
used as a constant expression for static_assert() (which requires a
constant expression[1][2]) when used on constant values. This must be
constructed manually, since __builtin_add_overflow() does not produce
a constant expression[3].

Additionally adds castable_to_type(), similar to __same_type(), but for
checking if a constant value would overflow if cast to a given type.

Add unit tests for overflows_type(), __same_type(), and castable_to_type()
to the existing KUnit "overflow" test:

[16:03:33] ================== overflow (21 subtests) ==================
...
[16:03:33] [PASSED] overflows_type_test
[16:03:33] [PASSED] same_type_test
[16:03:33] [PASSED] castable_to_type_test
[16:03:33] ==================== [PASSED] overflow =====================
[16:03:33] ============================================================
[16:03:33] Testing complete. Ran 21 tests: passed: 21
[16:03:33] Elapsed time: 24.022s total, 0.002s configuring, 22.598s building, 0.767s running

[1] https://en.cppreference.com/w/c/language/_Static_assert
[2] C11 standard (ISO/IEC 9899:2011): 6.7.10 Static assertions
[3] https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html
    6.56 Built-in Functions to Perform Arithmetic with Overflow Checking
    Built-in Function: bool __builtin_add_overflow (type1 a, type2 b,

Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Tom Rix <trix@redhat.com>
Cc: Daniel Latypov <dlatypov@google.com>
Cc: Vitor Massaru Iha <vitor@massaru.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Jani Nikula <jani.nikula@intel.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-hardening@vger.kernel.org
Cc: llvm@lists.linux.dev
Co-developed-by: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
Signed-off-by: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20221024201125.1416422-1-gwan-gyeong.mun@intel.com

Bug: 279506910
(cherry picked from commit 4b21d25bf5)
Change-Id: I20aff9de6b82a2f5203367d30555f904681a5b7b
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2023-05-16 20:35:28 +00:00
Treehugger Robot
25a4fdf787 Merge "Merge b1644a0031 ("drm/rockchip: vop2: Use regcache_sync() to fix suspend/resume") into android14-6.1" into android14-6.1 2023-05-16 18:34:57 +00:00
Dmytro Laktyushkin
26283282a1 UPSTREAM: drm/amd/display: set dcn315 lb bpp to 48
commit 6d9240c46f upstream.

[Why & How]
Fix a typo for dcn315 line buffer bpp.

Reviewed-by: Jun Lei <Jun.Lei@amd.com>
Acked-by: Qingqing Zhuo <qingqing.zhuo@amd.com>
Change-Id: I6f5408cd982d1ff478e6fb2982bd90c97184e692
Signed-off-by: Dmytro Laktyushkin <Dmytro.Laktyushkin@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 4ac57c3fe2)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-05-16 18:11:31 +00:00
Alan Liu
5d61392e80 UPSTREAM: drm/amdgpu: Fix desktop freezed after gpu-reset
commit c8b5a95b57 upstream.

[Why]
After gpu-reset, sometimes the driver fails to enable vblank irq,
causing flip_done timed out and the desktop freezed.

During gpu-reset, we disable and enable vblank irq in dm_suspend() and
dm_resume(). Later on in amdgpu_irq_gpu_reset_resume_helper(), we check
irqs' refcount and decide to enable or disable the irqs again.

However, we have 2 sets of API for controling vblank irq, one is
dm_vblank_get/put() and another is amdgpu_irq_get/put(). Each API has
its own refcount and flag to store the state of vblank irq, and they
are not synchronized.

In drm we use the first API to control vblank irq but in
amdgpu_irq_gpu_reset_resume_helper() we use the second set of API.

The failure happens when vblank irq was enabled by dm_vblank_get()
before gpu-reset, we have vblank->enabled true. However, during
gpu-reset, in amdgpu_irq_gpu_reset_resume_helper() vblank irq's state
checked from amdgpu_irq_update() is DISABLED. So finally it disables
vblank irq again. After gpu-reset, if there is a cursor plane commit,
the driver will try to enable vblank irq by calling drm_vblank_enable(),
but the vblank->enabled is still true, so it fails to turn on vblank
irq and causes flip_done can't be completed in vblank irq handler and
desktop become freezed.

[How]
Combining the 2 vblank control APIs by letting drm's API finally calls
amdgpu_irq's API, so the irq's refcount and state of both APIs can be
synchronized. Also add a check to prevent refcount from being less then
0 in amdgpu_irq_put().

v2:
- Add warning in amdgpu_irq_enable() if the irq is already disabled.
- Call dc_interrupt_set() in dm_set_vblank() to avoid refcount change
  if it is in gpu-reset.

v3:
- Improve commit message and code comments.

Change-Id: I44a9569645ce40ea1cf98fce4741c9e683160220
Signed-off-by: Alan Liu <HaoPing.Liu@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit bef774effb)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-05-16 18:11:31 +00:00