drm/lima: handle shared irq case for lima_pp_bcast_irq_handler
Subsystems (30)
Sasha Levin
maintainerPATCH 166/171 proc: use down_read_killable mmap_sem for /proc/pid/map_files
In reply to Sasha LevinFrom: Konstantin Khlebnikov <[email protected]>
[ Upstream commit cd9e2bb8271c971d9f37c722be2616c7f8ba0664 ]
Do not remain stuck forever if something goes wrong. Using a killable lock permits cleanup of stuck tasks and simplifies investigation.
It seems ->d_revalidate() could return any error (except ECHILD) to abort validation and pass error as result of lookup sequence.
--- fs/proc/base.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
fs/proc/base.c +22 -6
@@ -1962,9 +1962,12 @@ static int map_files_d_revalidate(struct dentry *dentry, unsigned int flags) goto out;if (!dname_to_vma_addr (dentry, &vm_start, &vm_end)) { -down_read (&mm->mmap_sem); - exact_vma_exists = !!find_exact_vma (mm, vm_start, vm_end); -up_read (&mm->mmap_sem); + status =down_read_killable (&mm->mmap_sem); +if (!status) { + exact_vma_exists = !!find_exact_vma (mm, vm_start, + vm_end); +up_read (&mm->mmap_sem); + } }mmput (mm);
@@ -2010,8 +2013,11 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)if (rc) goto out_mmput; + rc =down_read_killable (&mm->mmap_sem); +if (rc) + goto out_mmput; + rc = -ENOENT ; -down_read (&mm->mmap_sem); vma =find_exact_vma (mm, vm_start, vm_end);if (vma && vma->vm_file) { *path = vma->vm_file->f_path;
@@ -2107,7 +2113,11 @@ static struct dentry *proc_map_files_lookup(struct inode *dir,if (!mm) goto out_put_task; -down_read (&mm->mmap_sem); + result =ERR_PTR (-EINTR ); +if (down_read_killable (&mm->mmap_sem)) + goto out_put_mm; + + result =ERR_PTR (-ENOENT ); vma =find_exact_vma (mm, vm_start, vm_end);if (!vma) goto out_no_vma;
@@ -2118,6 +2128,7 @@ static struct dentry *proc_map_files_lookup(struct inode *dir, out_no_vma:up_read (&mm->mmap_sem); +out_put_mm:mmput (mm); out_put_task:put_task_struct (task);
@@ -2160,7 +2171,12 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) mm =get_task_mm (task);if (!mm) goto out_put_task; -down_read (&mm->mmap_sem); + + ret =down_read_killable (&mm->mmap_sem); +if (ret) { +mmput (mm); + goto out_put_task; + } nr_files =0 ;
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 167/171 cxgb4: reduce kernel stack usage in cudbg_collect_mem_region()
In reply to Sasha LevinFrom: Arnd Bergmann <[email protected]>
[ Upstream commit 752c2ea2d8e7c23b0f64e2e7d4337f3604d44c9f ]
The cudbg_collect_mem_region() and cudbg_read_fw_mem() both use several hundred kilobytes of kernel stack space. One gets inlined into the other, which causes the stack usage to be combined beyond the warning limit when building with clang:
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c:1057:12: error: stack frame size of 1244 bytes in function 'cudbg_collect_mem_region' [-Werror,-Wframe-larger-than=]
Restructuring cudbg_collect_mem_region() lets clang do the same optimization that gcc does and reuse the stack slots as it can see that the large variables are never used together.
A better fix might be to avoid using cudbg_meminfo on the stack altogether, but that requires a larger rewrite.
--- .../net/ethernet/chelsio/cxgb4/cudbg_lib.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c +13 -6
@@ -1054,14 +1054,12 @@ static void cudbg_t4_fwcache(struct cudbg_init *pdbg_init, } } -static int cudbg_collect_mem_region (struct cudbg_init *pdbg_init, -struct cudbg_buffer *dbg_buff, -struct cudbg_error *cudbg_err, -u8 mem_type) +static unsigned long cudbg_mem_region_size (struct cudbg_init *pdbg_init, +struct cudbg_error *cudbg_err, +u8 mem_type) {struct adapter *padap = pdbg_init->adap;struct cudbg_meminfo mem_info; -unsigned long size;u8 mc_idx;int rc;
@@ -1075,7 +1073,16 @@ static int cudbg_collect_mem_region(struct cudbg_init *pdbg_init,if (rc)return rc; - size = mem_info.avail[mc_idx].limit - mem_info.avail[mc_idx].base; +return mem_info.avail[mc_idx].limit - mem_info.avail[mc_idx].base; +} + +static int cudbg_collect_mem_region (struct cudbg_init *pdbg_init, +struct cudbg_buffer *dbg_buff, +struct cudbg_error *cudbg_err, +u8 mem_type) +{ +unsigned long size =cudbg_mem_region_size (pdbg_init, cudbg_err, mem_type); +return cudbg_read_fw_mem (pdbg_init, dbg_buff, mem_type, size, cudbg_err); }
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 168/171 proc: use down_read_killable mmap_sem for /proc/pid/maps
In reply to Sasha LevinFrom: Konstantin Khlebnikov <[email protected]>
[ Upstream commit 8a713e7df3352b8d9392476e9cf29e4e185dac32 ]
Do not remain stuck forever if something goes wrong. Using a killable lock permits cleanup of stuck tasks and simplifies investigation.
This function is also used for /proc/pid/smaps.
--- fs/proc/task_mmu.c | 6 +++++- fs/proc/task_nommu.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-)
fs/proc/task_mmu.c +5 -1
@@ -166,7 +166,11 @@ static void *m_start(struct seq_file *m, loff_t *ppos)if (!mm || !mmget_not_zero (mm))return NULL ; -down_read (&mm->mmap_sem); +if (down_read_killable (&mm->mmap_sem)) { +mmput (mm); +return ERR_PTR (-EINTR ); + } +hold_task_mempolicy (priv); priv->tail_vma =get_gate_vma (mm);
fs/proc/task_nommu.c +5 -1
@@ -211,7 +211,11 @@ static void *m_start(struct seq_file *m, loff_t *pos)if (!mm || !mmget_not_zero (mm))return NULL ; -down_read (&mm->mmap_sem); +if (down_read_killable (&mm->mmap_sem)) { +mmput (mm); +return ERR_PTR (-EINTR ); + } +/* start from the Nth VMA */ for (p =rb_first (&mm->mm_rb); p; p =rb_next (p))if (n-- ==0 )
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 169/171 locking/lockdep: Fix lock used or unused stats error
In reply to Sasha LevinFrom: Yuyang Du <[email protected]>
[ Upstream commit 68d41d8c94a31dfb8233ab90b9baf41a2ed2da68 ]
The stats variable nr_unused_locks is incremented every time a new lock class is register and decremented when the lock is first used in __lock_acquire(). And after all, it is shown and checked in lockdep_stats.
However, under configurations that either CONFIG_TRACE_IRQFLAGS or CONFIG_PROVE_LOCKING is not defined:
The commit:
091806515124b20 ("locking/lockdep: Consolidate lock usage bit initialization")
missed marking the LOCK_USED flag at IRQ usage initialization because as mark_usage() is not called. And the commit:
886532aee3cd42d ("locking/lockdep: Move mark_lock() inside CONFIG_TRACE_IRQFLAGS && CONFIG_PROVE_LOCKING")further made mark_lock() not defined such that the LOCK_USED cannot be marked at all when the lock is first acquired.
As a result, we fix this by not showing and checking the stats under such configurations for lockdep_stats.
--- kernel/locking/lockdep_proc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/locking/lockdep_proc.c +3 -2
@@ -210,6 +210,7 @@ static int lockdep_stats_show(struct seq_file *m, void *v) nr_hardirq_read_safe =0 , nr_hardirq_read_unsafe =0 , sum_forward_deps =0 ; +#ifdef CONFIG_PROVE_LOCKING list_for_each_entry (class, &all_lock_classes, lock_entry) {if (class->usage_mask ==0 )
@@ -241,12 +242,12 @@ static int lockdep_stats_show(struct seq_file *m, void *v)if (class->usage_mask &LOCKF_ENABLED_HARDIRQ_READ ) nr_hardirq_read_unsafe++; -#ifdef CONFIG_PROVE_LOCKING sum_forward_deps +=lockdep_count_forward_deps (class); -#endif }#ifdef CONFIG_DEBUG_LOCKDEP DEBUG_LOCKS_WARN_ON (debug_atomic_read (nr_unused_locks) != nr_unused); +#endif +#endif seq_printf (m," lock-classes: %11lu [max: %lu]\n" , nr_lock_classes,MAX_LOCKDEP_KEYS );
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 170/171 mm: use down_read_killable for locking mmap_sem in access_remote_vm
In reply to Sasha LevinFrom: Konstantin Khlebnikov <[email protected]>
[ Upstream commit 1e426fe28261b03f297992e89da3320b42816f4e ]
This function is used by ptrace and proc files like /proc/pid/cmdline and /proc/pid/environ.
Access_remote_vm never returns error codes, all errors are ignored and only size of successfully read data is returned. So, if current task was killed we'll simply return 0 (bytes read).
Mmap_sem could be locked for a long time or forever if something goes wrong. Using a killable lock permits cleanup of stuck tasks and simplifies investigation.
--- mm/memory.c | 4 +++- mm/nommu.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-)
mm/memory.c +3 -1
@@ -4349,7 +4349,9 @@ int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,void *old_buf = buf;int write = gup_flags &FOLL_WRITE ; -down_read (&mm->mmap_sem); +if (down_read_killable (&mm->mmap_sem)) +return 0 ; +/* ignore errors, just check how much was successfully transferred */ while (len) {int bytes, ret, offset;
mm/nommu.c +2 -1
@@ -1792,7 +1792,8 @@ int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,struct vm_area_struct *vma;int write = gup_flags &FOLL_WRITE ; -down_read (&mm->mmap_sem); +if (down_read_killable (&mm->mmap_sem)) +return 0 ;/* the access must start within one of the target process's mappings */ vma =find_vma (mm, addr);
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 171/171 mm, swap: fix race between swapoff and some swap operations
In reply to Sasha LevinFrom: Huang Ying <[email protected]>
[ Upstream commit eb085574a7526c4375965c5fbf7e5b0c19cdd336 ]
When swapin is performed, after getting the swap entry information from the page table, system will swap in the swap entry, without any lock held to prevent the swap device from being swapoff. This may cause the race like below,
CPU 1 CPU 2
----- -----
do_swap_page
swapin_readahead
__read_swap_cache_async
swapoff swapcache_prepare
p->swap_map = NULL __swap_duplicate
p->swap_map[?] /* !!! NULL pointer access */
Because swapoff is usually done when system shutdown only, the race may not hit many people in practice. But it is still a race need to be fixed.
To fix the race, get_swap_device() is added to check whether the specified swap entry is valid in its swap device. If so, it will keep the swap entry valid via preventing the swap device from being swapoff, until put_swap_device() is called.
Because swapoff() is very rare code path, to make the normal path runs as fast as possible, rcu_read_lock/unlock() and synchronize_rcu() instead of reference count is used to implement get/put_swap_device(). >From get_swap_device() to put_swap_device(), RCU reader side is locked, so synchronize_rcu() in swapoff() will wait until put_swap_device() is called.
In addition to swap_map, cluster_info, etc. data structure in the struct swap_info_struct, the swap cache radix tree will be freed after swapoff, so this patch fixes the race between swap cache looking up and swapoff too.
Races between some other swap cache usages and swapoff are fixed too via calling synchronize_rcu() between clearing PageSwapCache() and freeing swap cache data structure.
Another possible method to fix this is to use preempt_off() + stop_machine() to prevent the swap device from being swapoff when its data structure is being accessed. The overhead in hot-path of both methods is similar. The advantages of RCU based method are,
1. stop_machine() may disturb the normal execution code path on other CPUs.
2. File cache uses RCU to protect its radix tree. If the similar mechanism is used for swap cache too, it is easier to share code between them.
3. RCU is used to protect swap cache in total_swapcache_pages() and exit_swap_address_space() already. The two mechanisms can be merged to simplify the logic.
--- include/linux/swap.h | 13 +++- mm/memory.c | 2 +- mm/swap_state.c | 16 ++++- mm/swapfile.c | 154 ++++++++++++++++++++++++++++++++++--------- 4 files changed, 146 insertions(+), 39 deletions(-)
include/linux/swap.h +10 -3
@@ -175,8 +175,9 @@ enum {SWP_PAGE_DISCARD = (1 <<10 ),/* freed swap page-cluster discards */ SWP_STABLE_WRITES = (1 <<11 ),/* no overwrite PG_writeback pages */ SWP_SYNCHRONOUS_IO = (1 <<12 ),/* synchronous IO is efficient */ +SWP_VALID = (1 <<13 ),/* swap is valid to be operated on? */ /* add others here before... */ - SWP_SCANNING = (1 << 13), /* refcount in scan_swap_map */ + SWP_SCANNING = (1 << 14), /* refcount in scan_swap_map */ };#define SWAP_CLUSTER_MAX 32UL
@@ -460,7 +461,7 @@ extern unsigned int count_swap_pages(int, int);extern sector_t map_swap_page (struct page *,struct block_device **);extern sector_t swapdev_block (int ,pgoff_t );extern int page_swapcount (struct page *); -extern int __swap_count (struct swap_info_struct *si,swp_entry_t entry); +extern int __swap_count (swp_entry_t entry);extern int __swp_swapcount (swp_entry_t entry);extern int swp_swapcount (swp_entry_t entry);extern struct swap_info_struct *page_swap_info (struct page *);
@@ -470,6 +471,12 @@ extern int try_to_free_swap(struct page *);struct backing_dev_info ;extern int init_swap_address_space (unsigned int type,unsigned long nr_pages);extern void exit_swap_address_space (unsigned int type); +extern struct swap_info_struct *get_swap_device (swp_entry_t entry); + +static inline void put_swap_device (struct swap_info_struct *si) +{ +rcu_read_unlock (); +}#else /* CONFIG_SWAP */
@@ -576,7 +583,7 @@ static inline int page_swapcount(struct page *page)return 0 ; } -static inline int __swap_count (struct swap_info_struct *si,swp_entry_t entry) +static inline int __swap_count (swp_entry_t entry) {return 0 ; }
mm/memory.c +1 -1
@@ -2807,7 +2807,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)struct swap_info_struct *si =swp_swap_info (entry);if (si->flags &SWP_SYNCHRONOUS_IO && -__swap_count (si, entry) ==1 ) { +__swap_count (entry) ==1 ) {/* skip swapcache */ page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->address);
mm/swap_state.c +13 -3
@@ -310,8 +310,13 @@ struct page *lookup_swap_cache(swp_entry_t entry, struct vm_area_struct *vma, unsigned long addr) {struct page *page; +struct swap_info_struct *si; + si =get_swap_device (entry); +if (!si) +return NULL ; page =find_get_page (swap_address_space (entry),swp_offset (entry)); +put_swap_device (si);INC_CACHE_INFO (find_total);if (page) {
@@ -354,8 +359,8 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, struct vm_area_struct *vma, unsigned long addr, bool *new_page_allocated) { - struct page *found_page, *new_page = NULL; -struct address_space *swapper_space =swap_address_space (entry); + struct page *found_page = NULL, *new_page = NULL; +struct swap_info_struct *si;int err; *new_page_allocated = false;
@@ -365,7 +370,12 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,* called after lookup_swap_cache() failed, re-calling * that would confuse statistics. */ - found_page =find_get_page (swapper_space,swp_offset (entry)); + si =get_swap_device (entry); +if (!si) +break ; + found_page =find_get_page (swap_address_space (entry), +swp_offset (entry)); +put_swap_device (si);if (found_page)break ;
mm/swapfile.c +122 -32
264 lines not on this page · raw message
Signature · 1 line
2.20.1