Commit Graph

993184 Commits

Author SHA1 Message Date
Suren Baghdasaryan
66544e79f4 ANDROID: mm/khugepaged: add missing vm_write_{begin|end}
Speculative page fault handler needs to detect concurrent pmd changes
and relies on vma seqcount for that. pmdp_collapse_flush(), set_huge_pmd() and collapse_and_free_pmd() can modify a pmd.
vm_write_{begin|end} are needed in the paths which can call these
functions for page fault handler to detect pmd changes.

Bug: 257443051
Change-Id: Ieb784b5f44901b66a594f61b9e7c91190ff97f80
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2022-11-21 12:54:15 -08:00
Michel Lespinasse
2a3979df04 BACKPORT: FROMLIST: mm: implement speculative handling in filemap_fault()
Extend filemap_fault() to handle speculative faults.

In the speculative case, we will only be fishing existing pages out of
the page cache. The logic we use mirrors what is done in the
non-speculative case, assuming that pages are found in the page cache,
are up to date and not already locked, and that readahead is not
necessary at this time. In all other cases, the fault is aborted to be
handled non-speculatively.

Signed-off-by: Michel Lespinasse <michel@lespinasse.org>
Link: https://lore.kernel.org/all/20210407014502.24091-26-michel@lespinasse.org/

Conflicts:
    mm/filemap.c

1. Added back file_ra_state variable used by SPF path.
2. Updated comment for filemap_fault to reflect SPF locking rules.

Bug: 161210518
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I82eba7fcfc81876245c2e65bc5ae3d33ddfcc368
2022-11-21 10:55:56 -08:00
Suren Baghdasaryan
ec35e912e7 ANDROID: mm: prevent reads of unstable pmd during speculation
Checks of pmd during speculative page fault handling are racy because
pmd is unprotected and might be modified or cleared. This might cause
use-after-free reads from speculative path, therefore prevent such
checks. At the beginning of speculation pmd is checked to be valid and
if it's changed before page fault is handled, the change will be detected
and page fault will be retried under mmap_lock protection.

Bug: 257443051
Change-Id: I0cbd3b0b44e8296cf0d6cb298fae48c696580068
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2022-11-21 10:55:56 -08:00
Suren Baghdasaryan
ce7fa7020a ANDROID: mm: prevent speculative page fault handling for in do_swap_page()
do_swap_page() uses migration_entry_wait() which operates on page tables
without protection. Disable speculative page fault handling.

Bug: 257443051
Change-Id: I677eb1ee85707dce533d5d811dcde5f5dabcfdf3
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2022-11-21 10:55:56 -08:00
Suren Baghdasaryan
4812532ece ANDROID: mm: prevent speculative page fault handling for userfaults
handle_userfault() should be protected against a concurrent
userfaultfd_release(), therefore handling a userfaults speculatively
without mmap_lock protection should be disallowed.

Bug: 257443051
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Ic6ae39329c73e8849048ea15b5351a49346404d3
2022-11-21 10:55:56 -08:00
Suren Baghdasaryan
43247cf563 ANDROID: mm: skip pte_alloc during speculative page fault
Speculative page fault checks pmd to be valid before starting to handle
the page fault and pte_alloc() should do nothing if pmd stays valid.
If pmd gets changed during speculative page fault, we will detect the
change later and retry with mmap_lock. Therefore pte_alloc() can be
safely skipped and this prevents the racy pmd_lock() call which can
access pmd->ptl after pmd was cleared.

Bug: 257443051
Change-Id: Iec57df5530dba6e0e0bdf9f7500f910851c3d3fd
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2022-11-21 10:55:55 -08:00
Kever Yang
2f2dc42fbf ANDROID: GKI: rockchip: Add symbols for cpufreq
10 symbol(s) added
  'void cpufreq_dbs_governor_exit(struct cpufreq_policy *)'
  'int cpufreq_dbs_governor_init(struct cpufreq_policy *)'
  'void cpufreq_dbs_governor_limits(struct cpufreq_policy *)'
  'int cpufreq_dbs_governor_start(struct cpufreq_policy *)'
  'void cpufreq_dbs_governor_stop(struct cpufreq_policy *)'
  'void cpufreq_unregister_governor(struct cpufreq_governor *)'
  'unsigned int dbs_update(struct cpufreq_policy *)'
  'void dev_pm_opp_put_prop_name(struct opp_table *)'
  'void gov_update_cpu_data(struct dbs_data *)'
  'ssize_t store_sampling_rate(struct gov_attr_set *, const char *, size_t)'

Bug: 239396464
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Change-Id: I63597fe92f0279199173f0190ef6d3da4f0164f4
2022-11-21 16:56:07 +00:00
Khalid Shaik
c8f45c4915 ANDROID: Update the ABI representation
1 function symbol(s) added
  'int __traceiter_android_rvh_do_sched_yield(void *, struct rq *)'

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

Bug: 254608320

Change-Id: I4b2ed24711889914c901f55bce70fdef8da8ae0b
Signed-off-by: Khalid Shaik <khalid.s@samsung.com>
2022-11-18 22:03:51 +00:00
Tengfei Fan
0fabf2342f ANDROID: sched: add hook point in do_sched_yield()
When a task yields, it relinquishes the cpu and
scheduler is tasked to find another task.
However our vendor scheduler logic implementation
could return the same task leading to a loop where
the yielded task gets to run back, so add hook point
in do_sched_yield() for vendor can do some work
before task is scheduled.

Bug: 205804537
Change-Id: I6528c3f4b0ee360559ef9c97cb1eb2b2d1357870
Signed-off-by: Tengfei Fan <quic_tengfan@quicinc.com>
Signed-off-by: Sai Harshini Nimmala <quic_snimmala@quicinc.com>
Signed-off-by: Khalid Shaik <khalid.s@samsung.com>
2022-11-18 22:03:51 +00:00
David Brazdil
2aed2a7cb0 ANDROID: KVM: arm64: s2mpu: Fix SYNC latency regression
SysMMU_SYNCs provide an invalidation-complete signal to the S2MPU
driver but the latency can be quite high. Improve this by waiting for
all the SYNCs in parallel - separate the initiation of invalidation
barrier from waiting for completion. This way we initiate invalidation
on all SYNCs first, then wait for all of them to complete.

The previously introduced exponential-backoff only kicks in if the
SYNC_COMP_COMPLETE bit is not set after the parallel invalidation.

Bug: 249161451
Signed-off-by: David Brazdil <dbrazdil@google.com>
Change-Id: I9d544bc65f8633d376c7ccd65ea23195ca432964
2022-11-18 15:35:18 +00:00
David Brazdil
e1ea4666e1 ANDROID: KVM: arm64: iommu: Add host_stage2_idmap_complete
Add a new callback to pkvm_iommu_ops called after
host_stage2_idmap_apply on all IOMMU devices. This allows the drivers to
complete operations like invalidation in two stages.

Bug: 249161451
Signed-off-by: David Brazdil <dbrazdil@google.com>
Change-Id: I9c077fd2b18ce54ad67eb34ef16bc94428797419
2022-11-18 15:35:18 +00:00
Quentin Perret
15e65b4a22 ANDROID: KVM: arm64: Issue CMOs when tearing down shadow pages
On the guest teardown path, pKVM will zero the pages used to back the
guest shadow data structures before returning them to the host as they
may contain secrets (e.g. in the vCPU registers). However, the zeroing
is done using a cacheable alias, and CMOs are missing, hence giving the
host a potential opportunity to read the original content of the shadow
structs from memory.

Fix this by issuing CMOs after zeroing the pages.

Bug: 259551298
Change-Id: Id696d47d16e4c3fd870cb70b792eeb7f2282fc78
Signed-off-by: Quentin Perret <qperret@google.com>
2022-11-17 17:22:34 +00:00
Mark Fasheh
80fcf382d1 ANDROID: Add ashmem ioctl to return a unique file identifier
This will allow a client program to avoid redundant actions on ashmem
buffers which it has already seen.

Bug: 244233389
Change-Id: Ica57a8842ff163eae5f9eca8141b439091ec0940
Signed-off-by: Mark Fasheh <mfasheh@google.com>
2022-11-17 17:01:16 +00:00
Khalid Shaik
056ee87d05 ANDROID: Update the ABI representation
28 function symbol(s) added
  'int __platform_register_drivers(struct platform_driver * const *, unsigned int, struct module *)'
  'int dapm_pinctrl_event(struct snd_soc_dapm_widget *, struct snd_kcontrol *, int)'
  'struct dentry * debugfs_create_symlink(const char *, struct dentry *, const char *)'
  'ssize_t device_show_bool(struct device *, struct device_attribute *, char *)'
  'ssize_t device_show_int(struct device *, struct device_attribute *, char *)'
  'ssize_t device_store_bool(struct device *, struct device_attribute *, const char *, size_t)'
  'ssize_t device_store_int(struct device *, struct device_attribute *, const char *, size_t)'
  'void * devm_krealloc(struct device *, void *, size_t, gfp_t)'
  'struct pinctrl * pinctrl_get(struct device *)'
  'int pm_runtime_barrier(struct device *)'
  'void pm_runtime_no_callbacks(struct device *)'
  'struct proc_dir_entry * proc_symlink(const char *, struct proc_dir_entry *, const char *)'
  'int snd_hwdep_new(struct snd_card *, char *, int, struct snd_hwdep * *)'
  'void snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *)'
  'unsigned int snd_pcm_rate_range_to_bits(unsigned int, unsigned int)'
  'int snd_soc_bytes_info_ext(struct snd_kcontrol *, struct snd_ctl_elem_info *)'
  'void snd_soc_component_async_complete(struct snd_soc_component *)'
  'int snd_soc_component_update_bits_async(struct snd_soc_component *, unsigned int, unsigned int, unsigned int)'
  'int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *, const char *)'
  'int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *, const struct snd_soc_dapm_route *, int)'
  'struct snd_soc_dai * snd_soc_find_dai(const struct snd_soc_dai_link_component *)'
  'int snd_soc_get_xr_sx(struct snd_kcontrol *, struct snd_ctl_elem_value *)'
  'int snd_soc_info_xr_sx(struct snd_kcontrol *, struct snd_ctl_elem_info *)'
  'int snd_soc_put_xr_sx(struct snd_kcontrol *, struct snd_ctl_elem_value *)'
  'int snd_soc_tplg_component_load(struct snd_soc_component *, struct snd_soc_tplg_ops *, const struct firmware *, u32)'
  'int snd_soc_tplg_component_remove(struct snd_soc_component *, u32)'
  'int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *, const struct snd_soc_tplg_widget_events *, int, u16)'
  'void sysfs_remove_bin_file(struct kobject *, const struct bin_attribute *)'

Bug: 254608320

Change-Id: I8fbde2c3b7f2e68f58edc940315e28d9ffcc1e64
Signed-off-by: Khalid Shaik <khalid.s@samsung.com>
2022-11-17 16:14:21 +00:00
Will Deacon
b6cfd9d69f ANDROID: KVM: arm64: Fix repainting of PSCI SYSTEM_RESET2 calls
If the host issues a PSCI SYSTEM_RESET2 call requesting a warm reset
while guest pages are live in the system, then pKVM attempts to convert
this to a cold PSCI SYSTEM_RESET request to ensure the EL3 will clear
memory on the next boot. However, this logic is quite badly broken and
will instead attempt to take the 'mem_protect_lock' spinlock twice which
results in a deadlock.

Fix the repainting so that the 'host_ctxt' is updated inline and we
forward the updated request directly to EL3.

Signed-off-by: Will Deacon <will@kernel.org>
Bug: 259523340
Signed-off-by: Will Deacon <willdeacon@google.com>
Change-Id: I44719466b7f5abddf73730a3b74db13f935f92ec
2022-11-17 12:31:49 +00:00
Khalid Shaik
03b60942fe ANDROID: Update the ABI representation
15 function symbol(s) added
  'bool cfg80211_chandef_valid(const struct cfg80211_chan_def *)'
  'unsigned int cfg80211_classify8021d(struct sk_buff *, struct cfg80211_qos_map *)'
  'void cfg80211_conn_failed(struct net_device *, const u8 *, enum nl80211_connect_failed_reason, gfp_t)'
  'void cfg80211_ref_bss(struct wiphy *, struct cfg80211_bss *)'
  'int class_create_file_ns(struct class *, const struct class_attribute *, void *)'
  'int dev_vprintk_emit(int, const struct device *, const char *, va_list)'
  'void dma_heap_buffer_free(struct dma_buf *)'
  'int genlmsg_multicast_allns(const struct genl_family *, struct sk_buff *, u32, unsigned int, gfp_t)'
  'struct iio_channel * iio_channel_get_all(struct device *)'
  'void iio_channel_release(struct iio_channel *)'
  'int iio_read_channel_raw(struct iio_channel *, int *)'
  'int irq_get_irqchip_state(unsigned int, enum irqchip_irq_state, bool *)'
  'void kfree_skb_list(struct sk_buff *)'
  'int sg_nents_for_len(struct scatterlist *, u64)'
  'void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *)'

1 variable symbol(s) added
  'const struct kernel_param_ops param_ops_ullong'

Bug: 254608320

Change-Id: I043e6d162e0502bc007645bbead98c8eba2ca15b
Signed-off-by: Khalid Shaik <khalid.s@samsung.com>
2022-11-16 16:26:07 +00:00
Khalid Shaik
d08c3d3ba2 ANDROID: Update the ABI representation
22 function symbol(s) added
  'int __traceiter_android_vh_show_mem(void *, unsigned int, nodemask_t *)'
  'void __wake_up_locked_key(struct wait_queue_head *, unsigned int, void *)'
  'struct file * anon_inode_getfile(const char *, const struct file_operations *, void *, int)'
  'int dma_buf_get_flags(struct dma_buf *, unsigned long int *)'
  'int do_wait_intr(wait_queue_head_t *, wait_queue_entry_t *)'
  'struct file * get_task_exe_file(struct task_struct *)'
  's32 i2c_smbus_write_word_data(const struct i2c_client *, u8, u16)'
  'struct iio_dev * iio_device_alloc(struct device *, int)'
  'void iio_device_free(struct iio_dev *)'
  'int is_dma_buf_file(struct file *)'
  'int iterate_fd(struct files_struct *, unsigned int, int(*)(void *, struct file *, unsigned int), void *)'
  'bool printk_timed_ratelimit(unsigned long int *, unsigned int)'
  'void release_pages(struct page * *, int)'
  'int rtc_set_time(struct rtc_device *, struct rtc_time *)'
  'void * typec_get_drvdata(struct typec_port *)'
  'struct typec_partner * typec_register_partner(struct typec_port *, struct typec_partner_desc *)'
  'struct typec_port * typec_register_port(struct device *, const struct typec_capability *)'
  'void typec_set_data_role(struct typec_port *, enum typec_data_role)'
  'void typec_set_pwr_opmode(struct typec_port *, enum typec_pwr_opmode)'
  'void typec_set_pwr_role(struct typec_port *, enum typec_role)'
  'void typec_unregister_partner(struct typec_partner *)'
  'void typec_unregister_port(struct typec_port *)'

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

Bug: 254608320

Change-Id: I9aa8df7bf0a1545264fd99637d76e24e56bafc32
Signed-off-by: Khalid Shaik <khalid.s@samsung.com>
2022-11-16 16:25:35 +00:00
Khalid Shaik
01645da2f5 ANDROID: Update the ABI representation
20 function symbol(s) added
  'struct vm_struct * __get_vm_area_caller(unsigned long int, unsigned long int, unsigned long int, unsigned long int, void *)'
  'void console_lock()'
  'void console_stop(struct console *)'
  'int dapm_regulator_event(struct snd_soc_dapm_widget *, struct snd_kcontrol *, int)'
  'int devm_hwrng_register(struct device *, struct hwrng *)'
  'int map_kernel_range(unsigned long int, unsigned long int, pgprot_t, struct page * *)'
  'struct proc_dir_entry * proc_create_seq_private(const char *, umode_t, struct proc_dir_entry *, const struct seq_operations *, unsigned int, void *)'
  'int regulator_force_disable(struct regulator *)'
  'int regulator_set_mode(struct regulator *, unsigned int)'
  'struct snd_soc_dapm_widget * snd_soc_dapm_new_control(struct snd_soc_dapm_context *, const struct snd_soc_dapm_widget *)'
  'struct snd_soc_pcm_runtime * snd_soc_get_pcm_runtime(struct snd_soc_card *, struct snd_soc_dai_link *)'
  'void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *)'
  '__poll_t v4l2_ctrl_poll(struct file *, struct poll_table_struct *)'
  'int v4l2_ctrl_subscribe_event(struct v4l2_fh *, const struct v4l2_event_subscription *)'
  'int v4l2_event_unsubscribe(struct v4l2_fh *, const struct v4l2_event_subscription *)'
  'int v4l2_fh_is_singular(struct v4l2_fh *)'
  'int v4l2_fh_release(struct file *)'
  'int v4l2_m2m_querybuf(struct file *, struct v4l2_m2m_ctx *, struct v4l2_buffer *)'
  'int vb2_prepare_buf(struct vb2_queue *, struct media_device *, struct v4l2_buffer *)'
  'int vsprintf(char *, const char *, va_list)'

4 variable symbol(s) added
  'fb_mode_option'
  'atomic_t ignore_console_lock_warning'
  'struct kmem_cache * names_cachep'
  'struct bus_type spi_bus_type'

Bug: 254608320

Change-Id: I8cc3e8bf07945c9be7c27e325c56890cc4ab007a
Signed-off-by: Khalid Shaik <khalid.s@samsung.com>
2022-11-16 15:43:01 +00:00
Rick Yiu
6c86db3f70 ANDROID: Update the ABI representation
1 function symbol(s) added
  'void reweight_task(struct task_struct *, int)'

Bug: 245675204
Change-Id: I30841b0f9fe67009aaa3cace864df75d0f3b4bfc
Signed-off-by: Rick Yiu <rickyiu@google.com>
2022-11-16 08:05:18 +00:00
Rick Yiu
db144888f8 ANDROID: kernel: sched: Export reweight_task
Export reweight_task for vendor usage when they are trying to manipulate
task prio. After the prio changed, it will need to update its load
weight to take effect. Therefore, this function needs to be called
from vendor kernel module. It could be used with
trace_android_rvh_set_user_nice and trace_android_rvh_setscheduler.

Bug: 245675204
Change-Id: I0033518bf1cbd0a8129795743b95340f439d5fe8
Signed-off-by: Rick Yiu <rickyiu@google.com>
2022-11-16 08:05:18 +00:00
Jaegeuk Kim
6f642cd2f2 FROMGIT: f2fs: allow to read node block after shutdown
If block address is still alive, we should give a valid node block even after
shutdown. Otherwise, we can see zero data when reading out a file.

Bug: 257271565
Cc: stable@vger.kernel.org
Fixes: 83a3bfdb5a ("f2fs: indicate shutdown f2fs to allow unmount successfully")
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
(cherry picked from commit 6953bf65286d git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git dev)
Change-Id: Ifb70f6c73bd67d5112ee9fa1a5e4ad8e10ae8517
2022-11-15 19:18:47 +00:00
Ray Chi
92a7e867cf FROMGIT: usb: core: stop USB enumeration if too many retries
When a broken USB accessory connects to a USB host, usbcore might
keep doing enumeration retries. If the host has a watchdog mechanism,
the kernel panic will happen on the host.

This patch provides an attribute early_stop to limit the numbers of retries
for each port of a hub. If a port was marked with early_stop attribute,
unsuccessful connection attempts will fail quickly. In addition, if an
early_stop port has failed to initialize, it will ignore all future
connection events until early_stop attribute is clear.

Signed-off-by: Ray Chi <raychi@google.com>
Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/20221107072754.3336357-1-raychi@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Bug: 236915598
(cherry picked from commit 430d57f53e
https: //git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git/ usb-next)
Change-Id: Ib85522ca38c0f26ece9807d5304991853f155669
Signed-off-by: Ray Chi <raychi@google.com>
2022-11-15 04:54:20 +00:00
Will Deacon
f3fe2e6612 ANDROID: KVM: arm64: Adjust PSCI MEM_PROTECT refcount across share/unshare
When a protected guest shares or unshares a page with the host, we
should decrement and increment the PSCI MEM_PROTECT refcount respectively
since shared pages do not require poisoning on the reclaim path and will
therefore not be accounted for.

Bug: 258425493
Reported-by: Quentin Perret <qperret@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Change-Id: I80a4fad44de4313c6708a8259a1802ded379f03b
2022-11-15 04:05:41 +00:00
Matthew Wilcox (Oracle)
e7b635a520 BACKPORT: ext4,f2fs: fix readahead of verity data
The recent change of page_cache_ra_unbounded() arguments was buggy in the
two callers, causing us to readahead the wrong pages.  Move the definition
of ractl down to after the index is set correctly.  This affected
performance on configurations that use fs-verity.

Link: https://lkml.kernel.org/r/20221012193419.1453558-1-willy@infradead.org
Fixes: 73bb49da50 ("mm/readahead: make page_cache_ra_unbounded take a readahead_control")
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reported-by: Jintao Yin <nicememory@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bug: 258554362
(cherry picked from commit 4fa0e3ff21)
Change-Id: Ib5160c5c53629be328c370f5d5d464956d6a6312
Signed-off-by: Eric Biggers <ebiggers@google.com>
2022-11-15 01:01:59 +00:00
Khalid Shaik
c57ed31850 ANDROID: Update the ABI representation
39 function symbol(s) added
  'int __traceiter_android_rvh_can_migrate_task(void *, struct task_struct *, int, int *)'
  'int __traceiter_android_rvh_cpu_cgroup_can_attach(void *, struct cgroup_taskset *, int *)'
  'int __traceiter_android_rvh_find_busiest_queue(void *, int, struct sched_group *, struct cpumask *, struct rq * *, int *)'
  'int __traceiter_android_rvh_find_lowest_rq(void *, struct task_struct *, struct cpumask *, int, int *)'
  'int __traceiter_android_rvh_find_new_ilb(void *, struct cpumask *, int *)'
  'int __traceiter_android_rvh_replace_next_task_fair(void *, struct rq *, struct task_struct * *, struct sched_entity * *, bool *, bool, struct task_struct *)'
  'int __traceiter_android_rvh_sched_fork_init(void *, struct task_struct *)'
  'int __traceiter_android_rvh_sched_newidle_balance(void *, struct rq *, struct rq_flags *, int *, int *)'
  'int __traceiter_android_rvh_sched_nohz_balancer_kick(void *, struct rq *, unsigned int *, int *)'
  'int __traceiter_android_rvh_sched_rebalance_domains(void *, struct rq *, int *)'
  'int __traceiter_android_rvh_select_fallback_rq(void *, int, struct task_struct *, int *)'
  'int __traceiter_android_vh_binder_wakeup_ilocked(void *, struct task_struct *, bool, struct binder_proc *)'
  'int __traceiter_binder_transaction_received(void *, struct binder_transaction *)'
  'int __traceiter_ipi_entry(void *, const char *)'
  'int __traceiter_ipi_exit(void *, const char *)'
  'int __traceiter_ipi_raise(void *, const struct cpumask *, const char *)'
  'int _raw_write_trylock(rwlock_t *)'
  'void activate_task(struct rq *, struct task_struct *, int)'
  'caches_clean_inval_pou'
  'struct task_struct * cgroup_taskset_first(struct cgroup_taskset *, struct cgroup_subsys_state * *)'
  'struct task_struct * cgroup_taskset_next(struct cgroup_taskset *, struct cgroup_subsys_state * *)'
  'void cpu_hotplug_disable()'
  'void cpu_hotplug_enable()'
  'int cpufreq_frequency_table_get_index(struct cpufreq_policy *, unsigned int)'
  'struct cpuidle_driver * cpuidle_get_cpu_driver(struct cpuidle_device *)'
  'void deactivate_task(struct rq *, struct task_struct *, int)'
  'const struct cpumask * housekeeping_cpumask(enum hk_flags)'
  'u64 int_pow(u64, unsigned int)'
  'void kick_all_cpus_sync()'
  'ssize_t memory_read_from_buffer(void *, size_t, loff_t *, void *, size_t)'
  'int raw_notifier_chain_unregister(struct raw_notifier_head *, struct notifier_block *)'
  'struct reciprocal_value reciprocal_value(u32)'
  'void refresh_frequency_limits(struct cpufreq_policy *)'
  'void set_next_entity(struct cfs_rq *, struct sched_entity *)'
  'void set_task_cpu(struct task_struct *, unsigned int)'
  'void smp_call_function_many(const struct cpumask *, smp_call_func_t, void *, bool)'
  'bool stop_one_cpu_nowait(unsigned int, cpu_stop_fn_t, void *, struct cpu_stop_work *)'
  'const struct cpumask * system_32bit_el0_cpumask()'
  'void wake_up_if_idle(int)'

17 variable symbol(s) added
  'struct tracepoint __tracepoint_android_rvh_can_migrate_task'
  'struct tracepoint __tracepoint_android_rvh_cpu_cgroup_can_attach'
  'struct tracepoint __tracepoint_android_rvh_find_busiest_queue'
  'struct tracepoint __tracepoint_android_rvh_find_lowest_rq'
  'struct tracepoint __tracepoint_android_rvh_find_new_ilb'
  'struct tracepoint __tracepoint_android_rvh_replace_next_task_fair'
  'struct tracepoint __tracepoint_android_rvh_sched_fork_init'
  'struct tracepoint __tracepoint_android_rvh_sched_newidle_balance'
  'struct tracepoint __tracepoint_android_rvh_sched_nohz_balancer_kick'
  'struct tracepoint __tracepoint_android_rvh_sched_rebalance_domains'
  'struct tracepoint __tracepoint_android_rvh_select_fallback_rq'
  'struct tracepoint __tracepoint_android_vh_binder_wakeup_ilocked'
  'struct tracepoint __tracepoint_binder_transaction_received'
  'struct tracepoint __tracepoint_ipi_entry'
  'struct tracepoint __tracepoint_ipi_exit'
  'struct tracepoint __tracepoint_ipi_raise'
  'const char * const sched_feat_names[24]'

Bug: 254608320
Change-Id: Ie0a5acd2ecebf98572d99b31ee464dd161d7dd7b
Signed-off-by: Khalid Shaik <khalid.s@samsung.com>
2022-11-14 20:07:18 +00:00
Martin Liu
bcf1e503f5 ANDROID: adjust vendor hook to control blk_plug
We shouldn't hold lru_lock to proceed blk_finish_plug.

Fixes: 89fed37332 ("ANDROID: vendor hook to control blk_plug for shrink_lruvec")
Bug: 255471591
Change-Id: Ie9d9b0e4ee76b4735e802b2a202fbb79d0ae090e
Signed-off-by: Martin Liu <liumartin@google.com>
2022-11-14 19:50:30 +00:00
Akilesh Kailash
6cbaa88f4a ANDROID: dm-user: Remove bio recount in I/O path
When I/O is submitted to dm-user target, bio already
has a referance. Additional referance is not needed
in the I/O path.

Bug: 229696117
Test: OTA on Pixel
Change-Id: I8db6802e751336d7a10c6de0bc7a247a6d7f6b37
Signed-off-by: Akilesh Kailash <akailash@google.com>
2022-11-10 17:48:52 +00:00
Khalid Shaik
69e2e9275b ANDROID: Update the ABI representation
10 function symbol(s) added
  'int __traceiter_dwc3_ep_queue(void *, struct dwc3_request *)'
  'int __traceiter_hrtimer_expire_entry(void *, struct hrtimer *, ktime_t *)'
  'int __traceiter_hrtimer_expire_exit(void *, struct hrtimer *)'
  'int __traceiter_workqueue_execute_end(void *, struct work_struct *, work_func_t)'
  'int __traceiter_workqueue_execute_start(void *, struct work_struct *)'
  'int __v4l2_device_register_subdev_nodes(struct v4l2_device *, bool)'
  'void backlight_device_unregister(struct backlight_device *)'
  'struct clk * clk_register_composite(struct device *, const char *, const char * const *, int, struct clk_hw *, const struct clk_ops *, struct clk_hw *, const struct clk_ops *, struct clk_hw *, const struct clk_ops *, unsigned long int)'
  'struct regulator * regulator_get_exclusive(struct device *, const char *)'
  'void si_meminfo(struct sysinfo *)'

5 variable symbol(s) added
  'struct tracepoint __tracepoint_dwc3_ep_queue'
  'struct tracepoint __tracepoint_hrtimer_expire_entry'
  'struct tracepoint __tracepoint_hrtimer_expire_exit'
  'struct tracepoint __tracepoint_workqueue_execute_end'
  'struct tracepoint __tracepoint_workqueue_execute_start'

Bug: 254608320

Change-Id: I201e01cd83435b74bcafced862c508dcaba634c5
Signed-off-by: Khalid Shaik <khalid.s@samsung.com>
2022-11-10 10:04:30 +00:00
Sai Prakash Ranjan
501eeee6e2 UPSTREAM: irqchip/tegra: Fix overflow implicit truncation warnings
[ Upstream commit 443685992b ]

Fix -Woverflow warnings for tegra irqchip driver which is a result
of moving arm64 custom MMIO accessor macros to asm-generic function
implementations giving a bonus type-checking now and uncovering these
overflow warnings.

drivers/irqchip/irq-tegra.c: In function ‘tegra_ictlr_suspend’:
drivers/irqchip/irq-tegra.c:151:18: warning: large integer implicitly truncated to unsigned type [-Woverflow]
   writel_relaxed(~0ul, ictlr + ICTLR_COP_IER_CLR);
                  ^

Suggested-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Sai Prakash Ranjan <quic_saipraka@quicinc.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Cc: Marc Zyngier <maz@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Fixes: de3ce08049 ("irqchip: tegra: Add DT-based support for legacy interrupt controller")
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: Iaee226d0220c9774635cd51953d577ab7e2ebe77
Signed-off-by: Lee Jones <joneslee@google.com>
2022-11-10 10:00:14 +00:00
Sai Prakash Ranjan
13a5e047bd UPSTREAM: drm/meson: Fix overflow implicit truncation warnings
[ Upstream commit 98692f52c5 ]

Fix -Woverflow warnings for drm/meson driver which is a result
of moving arm64 custom MMIO accessor macros to asm-generic function
implementations giving a bonus type-checking now and uncovering these
overflow warnings.

drivers/gpu/drm/meson/meson_viu.c: In function ‘meson_viu_init’:
drivers/gpu/drm/meson/meson_registers.h:1826:48: error: large integer implicitly truncated to unsigned type [-Werror=overflow]
 #define  VIU_OSD_BLEND_REORDER(dest, src)      ((src) << (dest * 4))
                                                ^
drivers/gpu/drm/meson/meson_viu.c:472:18: note: in expansion of macro ‘VIU_OSD_BLEND_REORDER’
   writel_relaxed(VIU_OSD_BLEND_REORDER(0, 1) |
                  ^~~~~~~~~~~~~~~~~~~~~

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Sai Prakash Ranjan <quic_saipraka@quicinc.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Fixes: 147ae1cbaa ("drm: meson: viu: use proper macros instead of magic constants")
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: Id3502967ec9df74ea9420a34549bc0ac3c49dfa8
2022-11-10 09:55:51 +00:00
Hyunwoo Kim
55a2910224 UPSTREAM: video: fbdev: pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write
[ Upstream commit a09d2d00af ]

In pxa3xx_gcu_write, a count parameter of type size_t is passed to words of
type int.  Then, copy_from_user() may cause a heap overflow because it is used
as the third argument of copy_from_user().

Bug: 245928838
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
Signed-off-by: Helge Deller <deller@gmx.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: I9e21917a52e2cb78cc640a77a6eba21838aa8655
2022-11-10 09:53:36 +00:00
Marc Zyngier
52e7aa3245 FROMLIST: KVM: arm64: pkvm: Fixup boot mode to reflect that the kernel resumes from EL1
The kernel has an awfully complicated boot sequence in order to cope
with the various EL2 configurations, including those that "enhanced"
the architecture. We go from EL2 to EL1, then back to EL2, staying
at EL2 if VHE capable and otherwise go back to EL1.

Here's a paracetamol tablet for you.

The cpu_resume path follows the same logic, because coming up with
two versions of a square wheel is hard.

However, things aren't this straightforward with pKVM, as the host
resume path is always proxied by the hypervisor, which means that
the kernel is always entered at EL1. Which contradicts what the
__boot_cpu_mode[] array contains (it obviously says EL2).

This thus triggers a HVC call from EL1 to EL2 in a vain attempt
to upgrade from EL1 to EL2 VHE, which we are, funnily enough,
reluctant to grant to the host kernel. This is also completely
unexpected, and puzzles your average EL2 hacker.

Address it by fixing up the boot mode at the point the host gets
deprivileged. is_hyp_mode_available() and co already have a static
branch to deal with this, making it pretty safe.

Cc: <stable@vger.kernel.org> # 5.15+
Reported-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Tested-by: Vincent Donnefort <vdonnefort@google.com>
Bug: 258157858
Link: https://lore.kernel.org/all/20221108100138.3887862-1-vdonnefort@google.com/
Change-Id: I4a2269402ececa0ec47cab88343c3c623b4b2e3d
2022-11-09 15:27:20 +00:00
Khalid Shaik
bcb19fa296 ANDROID: GKI: Add symbol list for exynos
- Add Initial ABI Symbol list for Exynos SOC

20 function symbol(s) added
  'int __iio_device_register(struct iio_dev *, struct module *)'
  'int cpufreq_unregister_notifier(struct notifier_block *, unsigned int)'
  'int is_console_locked()'
  'struct __kernel_old_timeval ns_to_kernel_old_timeval(const s64)'
  'void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t)'
  'int sysfs_create_bin_file(struct kobject *, const struct bin_attribute *)'
  'int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *)'
  'int v4l2_device_register_subdev(struct v4l2_device *, struct v4l2_subdev *)'
  'int v4l2_device_set_name(struct v4l2_device *, const char *, atomic_t *)'
  'void v4l2_device_unregister_subdev(struct v4l2_subdev *)'
  'void v4l2_i2c_subdev_init(struct v4l2_subdev *, struct i2c_client *, const struct v4l2_subdev_ops *)'
  'int v4l2_m2m_dqbuf(struct file *, struct v4l2_m2m_ctx *, struct v4l2_buffer *)'
  'int v4l2_m2m_mmap(struct file *, struct v4l2_m2m_ctx *, struct vm_area_struct *)'
  '__poll_t v4l2_m2m_poll(struct file *, struct v4l2_m2m_ctx *, struct poll_table_struct *)'
  'int v4l2_m2m_reqbufs(struct file *, struct v4l2_m2m_ctx *, struct v4l2_requestbuffers *)'
  'int v4l2_m2m_streamoff(struct file *, struct v4l2_m2m_ctx *, enum v4l2_buf_type)'
  'int v4l2_m2m_streamon(struct file *, struct v4l2_m2m_ctx *, enum v4l2_buf_type)'
  'void v4l2_subdev_init(struct v4l2_subdev *, const struct v4l2_subdev_ops *)'
  'void v4l_bound_align_image(u32 *, unsigned int, unsigned int, unsigned int, u32 *, unsigned int, unsigned int, unsigned int, unsigned int)'
  'unsigned long int vmalloc_to_pfn(void *)'

1 variable symbol(s) added
  'const struct v4l2_subdev_ops v4l2_subdev_call_wrappers'

Bug: 254608320
Signed-off-by: Khalid Shaik <khalid.s@samsung.com>
Change-Id: I664d1eac2ba9b86fe29f978b8eb915c1386c9ba4
2022-11-09 10:44:02 +00:00
Peter Zijlstra
9e3ae1fbd3 UPSTREAM: sched: Fix yet more sched_fork() races
Where commit 4ef0c5c6b5 ("kernel/sched: Fix sched_fork() access an
invalid sched_task_group") fixed a fork race vs cgroup, it opened up a
race vs syscalls by not placing the task on the runqueue before it
gets exposed through the pidhash.

Commit 13765de814 ("sched/fair: Fix fault in reweight_entity") is
trying to fix a single instance of this, instead fix the whole class
of issues, effectively reverting this commit.

Bug: 255159688
Fixes: 4ef0c5c6b5 ("kernel/sched: Fix sched_fork() access an invalid sched_task_group")
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Tadeusz Struk <tadeusz.struk@linaro.org>
Tested-by: Zhang Qiao <zhangqiao22@huawei.com>
Tested-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Link: https://lkml.kernel.org/r/YgoeCbwj5mbCR0qA@hirez.programming.kicks-ass.net
(cherry picked from commit b1e8206582)
Signed-off-by: Woody Lin <woodylin@google.com>
Change-Id: Ic593aafb0cc8dae5ba382cdc4ab68526973fdfca
2022-11-09 10:22:02 +00:00
Ryan Roberts
3de7d142cf BACKPORT: KVM: arm64: Fix bad dereference on MTE-enabled systems
enter_exception64() performs an MTE check, which involves dereferencing
vcpu->kvm. While vcpu has already been fixed up to be a HYP VA pointer,
kvm is still a pointer in the kernel VA space.

This only affects nVHE configurations with MTE enabled, as in other
cases, the pointer is either valid (VHE) or not dereferenced (!MTE).

Fix this by first converting kvm to a HYP VA pointer.

Fixes: ea7fc1bb1c ("KVM: arm64: Introduce MTE VM feature")
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: Steven Price <steven.price@arm.com>
[maz: commit message tidy-up]
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20221027120945.29679-1-ryan.roberts@arm.com
(cherry picked from commit b6bcdc9f6b)
[willdeacon@: Fixed conflict with aosp/2038249 rework moving MTE feature
 check into caller]
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Bug: 233588291
Change-Id: Id0aac0fc38dff2569081910af7468ecf97b6eca3
2022-11-08 13:42:11 +00:00
Carlos Llamas
b684150a44 FROMLIST: binder: fix UAF of alloc->vma in race with munmap()
In commit 720c241924 ("ANDROID: binder: change down_write to
down_read") binder assumed the mmap read lock is sufficient to protect
alloc->vma inside binder_update_page_range(). This used to be accurate
until commit dd2283f260 ("mm: mmap: zap pages with read mmap_sem in
munmap"), which now downgrades the mmap_lock after detaching the vma
from the rbtree in munmap(). Then it proceeds to teardown and free the
vma with only the read lock held.

This means that accesses to alloc->vma in binder_update_page_range() now
will race with vm_area_free() in munmap() and can cause a UAF as shown
in the following KASAN trace:

  ==================================================================
  BUG: KASAN: use-after-free in vm_insert_page+0x7c/0x1f0
  Read of size 8 at addr ffff16204ad00600 by task server/558

  CPU: 3 PID: 558 Comm: server Not tainted 5.10.150-00001-gdc8dcf942daa #1
  Hardware name: linux,dummy-virt (DT)
  Call trace:
   dump_backtrace+0x0/0x2a0
   show_stack+0x18/0x2c
   dump_stack+0xf8/0x164
   print_address_description.constprop.0+0x9c/0x538
   kasan_report+0x120/0x200
   __asan_load8+0xa0/0xc4
   vm_insert_page+0x7c/0x1f0
   binder_update_page_range+0x278/0x50c
   binder_alloc_new_buf+0x3f0/0xba0
   binder_transaction+0x64c/0x3040
   binder_thread_write+0x924/0x2020
   binder_ioctl+0x1610/0x2e5c
   __arm64_sys_ioctl+0xd4/0x120
   el0_svc_common.constprop.0+0xac/0x270
   do_el0_svc+0x38/0xa0
   el0_svc+0x1c/0x2c
   el0_sync_handler+0xe8/0x114
   el0_sync+0x180/0x1c0

  Allocated by task 559:
   kasan_save_stack+0x38/0x6c
   __kasan_kmalloc.constprop.0+0xe4/0xf0
   kasan_slab_alloc+0x18/0x2c
   kmem_cache_alloc+0x1b0/0x2d0
   vm_area_alloc+0x28/0x94
   mmap_region+0x378/0x920
   do_mmap+0x3f0/0x600
   vm_mmap_pgoff+0x150/0x17c
   ksys_mmap_pgoff+0x284/0x2dc
   __arm64_sys_mmap+0x84/0xa4
   el0_svc_common.constprop.0+0xac/0x270
   do_el0_svc+0x38/0xa0
   el0_svc+0x1c/0x2c
   el0_sync_handler+0xe8/0x114
   el0_sync+0x180/0x1c0

  Freed by task 560:
   kasan_save_stack+0x38/0x6c
   kasan_set_track+0x28/0x40
   kasan_set_free_info+0x24/0x4c
   __kasan_slab_free+0x100/0x164
   kasan_slab_free+0x14/0x20
   kmem_cache_free+0xc4/0x34c
   vm_area_free+0x1c/0x2c
   remove_vma+0x7c/0x94
   __do_munmap+0x358/0x710
   __vm_munmap+0xbc/0x130
   __arm64_sys_munmap+0x4c/0x64
   el0_svc_common.constprop.0+0xac/0x270
   do_el0_svc+0x38/0xa0
   el0_svc+0x1c/0x2c
   el0_sync_handler+0xe8/0x114
   el0_sync+0x180/0x1c0

  [...]
  ==================================================================

To prevent the race above, revert back to taking the mmap write lock
inside binder_update_page_range(). One might expect an increase of mmap
lock contention. However, binder already serializes these calls via top
level alloc->mutex. Also, there was no performance impact shown when
running the binder benchmark tests.

Note this patch is specific to stable branches 5.4 and 5.10. Since in
newer kernel releases binder no longer caches a pointer to the vma.
Instead, it has been refactored to use vma_lookup() which avoids the
issue described here. This switch was introduced in commit a43cfc87ca
("android: binder: stop saving a pointer to the VMA").

Bug: 254837884
Link: https://lore.kernel.org/all/20221104175450.306810-1-cmllamas@google.com/
Fixes: dd2283f260 ("mm: mmap: zap pages with read mmap_sem in munmap")
Reported-by: Jann Horn <jannh@google.com>
Cc: <stable@vger.kernel.org> # 5.10.x
Cc: Minchan Kim <minchan@kernel.org>
Cc: Yang Shi <yang.shi@linux.alibaba.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Signed-off-by: Carlos Llamas <cmllamas@google.com>
Change-Id: Ieabadbfa30f99812da9c226cf1ddd5e60f62c607
2022-11-04 18:09:22 +00:00
Minchan Kim
9ffd177dce ANDROID: Update the ABI representation
1 function symbol(s) added
  'int __traceiter_android_vh_shrink_lruvec_blk_plug(void *, bool *)'

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

Bug: 255471591
Bug: 238728493
Change-Id: I8746bbe2f7ccc09e366deed6aa00bc4834643084
Signed-off-by: Minchan Kim <minchan@google.com>
2022-11-03 19:40:25 +00:00
Minchan Kim
89fed37332 ANDROID: vendor hook to control blk_plug for shrink_lruvec
Add vendor hook to contorl blk plugging for shrink_lruvec.

Bug: 255471591
Bug: 238728493
Change-Id: Iba2603ff2e1b62cf2ee8fd6969d8ccd71416a288
Signed-off-by: Minchan Kim <minchan@google.com>
2022-11-03 19:40:25 +00:00
Jann Horn
c0ce22abf7 UPSTREAM: mm: Fix TLB flush for not-first PFNMAP mappings in unmap_region()
This is a stable-specific patch.
I botched the stable-specific rewrite of
commit b67fbebd4c ("mmu_gather: Force tlb-flush VM_PFNMAP vmas"):
As Hugh pointed out, unmap_region() actually operates on a list of VMAs,
and the variable "vma" merely points to the first VMA in that list.
So if we want to check whether any of the VMAs we're operating on is
PFNMAP or MIXEDMAP, we have to iterate through the list and check each VMA.

Bug: 245812080
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 3998dc50eb)
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: I115183f65fc7df5d33264e6211adcd2ec531d996
2022-11-03 16:42:11 +00:00
Herbert Xu
75c194cf1a UPSTREAM: af_key: Do not call xfrm_probe_algs in parallel
[ Upstream commit ba953a9d89 ]

When namespace support was added to xfrm/afkey, it caused the
previously single-threaded call to xfrm_probe_algs to become
multi-threaded.  This is buggy and needs to be fixed with a mutex.

Bug: 245674737
Reported-by: Abhishek Shah <abhishek.shah@columbia.edu>
Fixes: 283bc9f35b ("xfrm: Namespacify xfrm state/policy locks")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Change-Id: I71fb89a999447862a6c4b1ff754378bb0452ad3a
Signed-off-by: Lee Jones <joneslee@google.com>
2022-11-03 15:26:32 +00:00
Jann Horn
8812ab3f9d UPSTREAM: mm: Force TLB flush for PFNMAP mappings before unlink_file_vma()
commit b67fbebd4c upstream.

Some drivers rely on having all VMAs through which a PFN might be
accessible listed in the rmap for correctness.
However, on X86, it was possible for a VMA with stale TLB entries
to not be listed in the rmap.

This was fixed in mainline with
commit b67fbebd4c ("mmu_gather: Force tlb-flush VM_PFNMAP vmas"),
but that commit relies on preceding refactoring in
commit 18ba064e42 ("mmu_gather: Let there be one tlb_{start,end}_vma()
implementation") and commit 1e9fdf21a4 ("mmu_gather: Remove per arch
tlb_{start,end}_vma()").

This patch provides equivalent protection without needing that
refactoring, by forcing a TLB flush between removing PTEs in
unmap_vmas() and the call to unlink_file_vma() in free_pgtables().

Bug: 245812080
[This is a stable-specific rewrite of the upstream commit!]
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: I8f539ff0365fb9b5d10fddb84082d5995348b897
2022-11-03 15:25:08 +00:00
Fuad Tabba
4e97b7ff2b ANDROID: KVM: arm64: Donate memory per vcpu for each vcpu shadow state
Memory donated to the hypervisor needs to be contiguous, which
might be difficult to find. To improve the odds of finding
contiguous memory, break up vcpu state donations per vcpu.

Bug: 232070947
Signed-off-by: Fuad Tabba <tabba@google.com>
Change-Id: Iff19b2e2b6ca58b1e6ef38c4b0f16c80dae34ab9
2022-11-03 02:20:01 +00:00
Fuad Tabba
6a7700c5b5 ANDROID: KVM: arm64: Initialize shadow vcpus with separate hypercalls
This is done as the first step towards donating memory per vcpu
in future patches without having to spend potentially too much
time in one hypercall.

Moreover, this has the nice effect of removing the need for
stashing the host vcpus in the memory donated for the pgd.

Bug: 232070947
Signed-off-by: Fuad Tabba <tabba@google.com>
Change-Id: I491c358fa29dd62ffc45347d6288696c846d5fc3
2022-11-03 02:20:01 +00:00
Fuad Tabba
0b7f3b9652 ANDROID: KVM: arm64: Refactor unpinning host vcpu
Factor out unpinning a single host vcpu from unpin_host_vcpus(),
since it will be used in a future patch in the error path.

No functional change intended.

Bug: 232070947
Signed-off-by: Fuad Tabba <tabba@google.com>
Change-Id: I321e41ae624b2daae8fc917432be0673e32235aa
2022-11-03 02:20:01 +00:00
Fuad Tabba
d345371dd2 ANDROID: KVM: arm64: Separate functions for shadow vm and vcpu init
Facilitates future patches that move the initialization of the
shadow vcpu to a separate hyp call.

Removed unused parameter (vcpu_array/pgd) from
init_shadow_structs().

No functional change intended.

Bug: 232070947
Signed-off-by: Fuad Tabba <tabba@google.com>
Change-Id: I5c3116e7558d958c03ea28dc5610122696a1fca2
2022-11-03 02:20:01 +00:00
Fuad Tabba
66be6be8fb ANDROID: KVM: arm64: Refactor code for reclaiming guest memory into a function
Tidies up code and enables the reuse of this function.

No functional change intended.

Bug: 232070947
Signed-off-by: Fuad Tabba <tabba@google.com>
Change-Id: I3a93dd0284e3c177b12d0cabf5e99747dceb0fb4
2022-11-03 02:20:01 +00:00
Minchan Kim
232bdcbd66 ANDROID: pass argument in zap_pte_range vendor hooks
We need to carry on state from zap_pte_range_tlb_start to
zap_pte_range_tlb_end.

The new param on the function stack will keep the function
trace_android_vh_zap_pte_range_tlb_start called or not and
pass the state to trace_android_vh_zap_pte_range_tlb_end.

Thus, trace_android_vh_zap_pte_range_tlb_end will know
the trace_android_vh_zap_pte_range_tlb_start was called.
If it was called, trace_android_vh_zap_pte_range_tlb_end
will do action to make pair. Otherwise, just skip it.

Bug: 238728493
Bug: 256549265
Change-Id: I95706d51da66f916ede626686483523f3b68dacb
Signed-off-by: Minchan Kim <minchan@google.com>
2022-11-02 15:53:39 +00:00
Kever Yang
a83ef907f0 ANDROID: GKI: Add for rockchip platform basic symbol
52 function symbol(s) added
  'int __clk_mux_determine_rate(struct clk_hw *, struct clk_rate_request *)'
  'int __genphy_config_aneg(struct phy_device *, bool)'
  'int __kfifo_to_user(struct __kfifo *, void *, unsigned long int, unsigned int *)'
  'unsigned int _bcd2bin(unsigned char)'
  'unsigned char _bin2bcd(unsigned int)'
  'void clk_bulk_put(int, struct clk_bulk_data *)'
  'struct clk_hw * clk_hw_register_composite(struct device *, const char *, const char * const *, int, struct clk_hw *, const struct clk_ops *, struct clk_hw *, const struct clk_ops *, struct clk_hw *, const struct clk_ops *, unsigned long int)'
  'struct clk * clk_register_divider_table(struct device *, const char *, const char *, unsigned long int, void *, u8, u8, u8, const struct clk_div_table *, spinlock_t *)'
  'struct clk * clk_register_mux_table(struct device *, const char *, const char * const *, u8, unsigned long int, void *, u8, u32, u8, u32 *, spinlock_t *)'
  'struct opp_table * dev_pm_opp_register_set_opp_helper(struct device *, int(*)(struct dev_pm_set_opp_data *))'
  'struct opp_table * dev_pm_opp_set_prop_name(struct device *, const char *)'
  'void dev_pm_opp_unregister_set_opp_helper(struct opp_table *)'
  'int devfreq_event_disable_edev(struct devfreq_event_dev *)'
  'int devfreq_event_enable_edev(struct devfreq_event_dev *)'
  'struct devfreq_event_dev * devfreq_event_get_edev_by_phandle(struct device *, const char *, int)'
  'int devfreq_event_get_edev_count(struct device *, const char *)'
  'int devfreq_event_get_event(struct devfreq_event_dev *, struct devfreq_event_data *)'
  'struct devfreq_event_dev * devm_devfreq_event_add_edev(struct device *, struct devfreq_event_desc *)'
  'int devm_devfreq_register_opp_notifier(struct device *, struct devfreq *)'
  'int down_write_trylock(struct rw_semaphore *)'
  'int genphy_resume(struct phy_device *)'
  'int genphy_soft_reset(struct phy_device *)'
  'int genphy_suspend(struct phy_device *)'
  's32 i2c_smbus_read_i2c_block_data(const struct i2c_client *, u8, u8, u8 *)'
  's32 i2c_smbus_write_i2c_block_data(const struct i2c_client *, u8, u8, const u8 *)'
  'struct iio_poll_func * iio_alloc_pollfunc(irqreturn_t(*)(int, void *), irqreturn_t(*)(int, void *), int, struct iio_dev *, const char *, ...)'
  'void iio_buffer_init(struct iio_buffer *)'
  'void iio_buffer_put(struct iio_buffer *)'
  'void iio_dealloc_pollfunc(struct iio_poll_func *)'
  'void iio_device_attach_buffer(struct iio_dev *, struct iio_buffer *)'
  's64 iio_get_time_ns(const struct iio_dev *)'
  'int iio_push_to_buffers(struct iio_dev *, void *)'
  'void iio_trigger_notify_done(struct iio_trigger *)'
  'int match_string(const char * const *, size_t, const char *)'
  'int mdiobus_read(struct mii_bus *, int, u32)'
  'int mdiobus_write(struct mii_bus *, int, u32, u16)'
  'unsigned int of_clk_get_parent_count(const struct device_node *)'
  'struct nvmem_cell * of_nvmem_cell_get(struct device_node *, const char *)'
  'int phy_drivers_register(struct phy_driver *, int, struct module *)'
  'void phy_drivers_unregister(struct phy_driver *, int)'
  'int pm_clk_add(struct device *, const char *)'
  'int pm_clk_add_clk(struct device *, struct clk *)'
  'int pm_clk_create(struct device *)'
  'void pm_clk_destroy(struct device *)'
  'int pm_clk_resume(struct device *)'
  'int pm_clk_suspend(struct device *)'
  'unsigned int regulator_get_linear_step(struct regulator *)'
  'int regulator_register_notifier(struct regulator *, struct notifier_block *)'
  'int regulator_unregister_notifier(struct regulator *, struct notifier_block *)'
  'int reset_controller_register(struct reset_controller_dev *)'
  'int scmi_driver_register(struct scmi_driver *, struct module *, const char *)'
  'void scmi_driver_unregister(struct scmi_driver *)'

7 variable symbol(s) added
  'const struct clk_ops clk_divider_ops'
  'const struct clk_ops clk_divider_ro_ops'
  'const struct clk_ops clk_fractional_divider_ops'
  'const struct clk_ops clk_gate_ops'
  'const struct clk_ops clk_mux_ops'
  'const struct clk_ops clk_mux_ro_ops'
  'struct workqueue_struct * system_freezable_wq'

Bug: 239396464
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I568d224fbebb463f44bf73d2dd286823286c106a
Signed-off-by: Giuliano Procida <gprocida@google.com>
2022-11-02 15:52:56 +00:00
Giuliano Procida
05c1e5a6fd ANDROID: GKI: Add Bazel rockchip symbol list entry
Bug: 239396464
Fixes: 788ba5e9de ("ANDROID: GKI: Add build for rockchip platform")
Change-Id: Ided3414a57a745e18b253bd4f5fb34b0738e364e
Signed-off-by: Giuliano Procida <gprocida@google.com>
2022-11-02 15:52:56 +00:00
Peter Collingbourne
56e639d3ff ANDROID: sched: check on_rq in freezer_should_skip()
In aosp/1979327 we attempted to prevent tasks with pending signals and
PF_FREEZER_SKIP from being immediately rescheduled, because such tasks
would crash the kernel if run while no capable CPUs were online. This was
implemented by declining to immediately reschedule them unless various
conditions were met. However, this ended up causing signals to fail to
be delivered if the signal was received while a task is processing a
syscall, such as futex(2), that will block with PF_FREEZER_SKIP set,
as the kernel relies on a check for TIF_SIGPENDING after setting the
task state to TASK_INTERRUPTIBLE in order to deliver such a signal.

This patch is an alternative solution to the original problem that
avoids introducing the signal delivery bug. It works by changing
how freezer_should_skip() is implemented. Instead of just checking
PF_FREEZER_SKIP, we also use the on_rq field to check whether the task
is not on a runqueue. In this way we ensure that a task that will be
immediately rescheduled will not return true from freezer_should_skip(),
and the task will block the freezer unless it is actually taken off
the runqueue.

Signed-off-by: Peter Collingbourne <pcc@google.com>
Bug: 202918514
Bug: 251700836
Change-Id: I3f9b705ce9ad2ca1d2df959f43cf05bef78560f8
2022-11-01 19:26:12 -07:00