mm: fix sparse warnings
Subsystems (6)
cover mm: fix sparse warnings
Hello,
This patchset tries to remove various warnings from sparse. Each patch contains the warnings it removes in changelog. I compile-tested with all{yes,no}config on x86. Any comments would be welcomed.
Thanks.
---
Namhyung Kim (12):
mm: remove temporary variable on generic_file_direct_write()
mm: add casts to/from gfp_t in gfp_to_alloc_flags()
mm: wrap get_locked_pte() using __cond_lock()
mm: add lock release annotation on do_wp_page()
mm: wrap follow_pte() using __cond_lock()
rmap: annotate lock context change on page_[un]lock_anon_vma()
rmap: wrap page_check_address() using __cond_lock()
rmap: make anon_vma_[chain_]free() static
vmalloc: rename temporary variable in __insert_vmap_area()
vmalloc: annotate lock context change on s_start/stop()
mm: declare some external symbols
vmstat: include compaction.h when CONFIG_COMPACTION
include/linux/backing-dev.h | 1 + include/linux/mm.h | 10 +++++++++- include/linux/rmap.h | 29 ++++++++++++++++++++++++++--- include/linux/writeback.h | 2 ++ mm/filemap.c | 8 ++++---- mm/memory.c | 16 ++++++++++++++-- mm/page_alloc.c | 4 ++-- mm/rmap.c | 10 ++++++---- mm/vmalloc.c | 10 ++++++---- mm/vmstat.c | 2 ++ 10 files changed, 72 insertions(+), 20 deletions(-)
--
1.7.2.2
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/12 mm: remove temporary variable on generic_file_direct_write()
'end' shadows earlier one and is not necessary at all. Remove it and use 'pos' instead. This removes following sparse warnings:
mm/filemap.c:2180:24: warning: symbol 'end' shadows an earlier one mm/filemap.c:2132:25: originally declared here
--- mm/filemap.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
mm/filemap.c +4 -4
@@ -2177,12 +2177,12 @@ generic_file_direct_write(struct kiocb *iocb, const struct iovec *iov, }if (written >0 ) { -loff_t end = pos + written; -if (end >i_size_read (inode) && !S_ISBLK (inode->i_mode)) { -i_size_write (inode, end); + pos += written; +if (pos >i_size_read (inode) && !S_ISBLK (inode->i_mode)) { +i_size_write (inode, pos);mark_inode_dirty (inode); } - *ppos = end; + *ppos = pos; } out:return written;
Signature · 7 lines
1.7.2.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/12 mm: add casts to/from gfp_t in gfp_to_alloc_flags()
In reply to Namhyung KimThis removes following warning from sparse:
mm/page_alloc.c:1934:9: warning: restricted gfp_t degrades to integer
--- mm/page_alloc.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
mm/page_alloc.c +2 -2
@@ -1931,7 +1931,7 @@ gfp_to_alloc_flags(gfp_t gfp_mask)const gfp_t wait = gfp_mask & __GFP_WAIT;/* __GFP_HIGH is assumed to be the same as ALLOC_HIGH to save a branch. */ -BUILD_BUG_ON (__GFP_HIGH !=ALLOC_HIGH ); +BUILD_BUG_ON (__GFP_HIGH != (__force gfp_t )ALLOC_HIGH );/* * The caller may dip into page reserves a bit more if the caller
@@ -1939,7 +1939,7 @@ gfp_to_alloc_flags(gfp_t gfp_mask)* policy or is asking for __GFP_HIGH memory. GFP_ATOMIC requests will * set both ALLOC_HARDER (!wait) and ALLOC_HIGH (__GFP_HIGH). */ - alloc_flags |= (gfp_mask & __GFP_HIGH); + alloc_flags |= (__force int ) (gfp_mask & __GFP_HIGH);if (!wait) { alloc_flags |=ALLOC_HARDER ;
Signature · 7 lines
1.7.2.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/12 mm: wrap get_locked_pte() using __cond_lock()
In reply to Namhyung KimThe get_locked_pte() conditionally grabs 'ptl' in case of returning non-NULL. This leads sparse to complain about context imbalance. Rename and wrap it using __cond_lock() to make sparse happy.
--- include/linux/mm.h | 10 +++++++++- mm/memory.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-)
include/linux/mm.h +9 -1
@@ -1023,7 +1023,15 @@ extern void unregister_shrinker(struct shrinker *);int vma_wants_writenotify (struct vm_area_struct *vma); -extern pte_t *get_locked_pte (struct mm_struct *mm,unsigned long addr,spinlock_t **ptl); +extern pte_t *__get_locked_pte (struct mm_struct *mm,unsigned long addr, +spinlock_t **ptl); +static inline pte_t *get_locked_pte (struct mm_struct *mm,unsigned long addr, +spinlock_t **ptl) +{ +pte_t *ptep; +__cond_lock (*ptl, ptep =__get_locked_pte (mm, addr, ptl)); +return ptep; +}#ifdef __PAGETABLE_PUD_FOLDED static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
mm/memory.c +1 -1
@@ -1590,7 +1590,7 @@ struct page *get_dump_page(unsigned long addr) }#endif /* CONFIG_ELF_CORE */ -pte_t *get_locked_pte (struct mm_struct *mm,unsigned long addr, +pte_t *__get_locked_pte (struct mm_struct *mm,unsigned long addr,spinlock_t **ptl) {pgd_t * pgd =pgd_offset (mm, addr);
Signature · 7 lines
1.7.2.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/12 mm: add lock release annotation on do_wp_page()
In reply to Namhyung KimThe do_wp_page() releases @ptl but was missing proper annotation. Add it. This removes following warnings from sparse:
mm/memory.c:2337:9: warning: context imbalance in 'do_wp_page' - unexpected unlock mm/memory.c:3142:19: warning: context imbalance in 'handle_mm_fault' - different lock contexts for basic block
--- mm/memory.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
mm/memory.c +1 -0
@@ -2107,6 +2107,7 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lostatic int do_wp_page (struct mm_struct *mm,struct vm_area_struct *vma,unsigned long address,pte_t *page_table,pmd_t *pmd,spinlock_t *ptl,pte_t orig_pte) +__releases (ptl) {struct page *old_page, *new_page;pte_t entry;
Signature · 7 lines
1.7.2.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 5/12 mm: wrap follow_pte() using __cond_lock()
In reply to Namhyung KimThe follow_pte() conditionally grabs *@ptlp in case of returning 0. Rename and wrap it using __cond_lock() removes following warnings:
mm/memory.c:2337:9: warning: context imbalance in 'do_wp_page' - unexpected unlock mm/memory.c:3142:19: warning: context imbalance in 'handle_mm_fault' - different lock contexts for basic block
--- mm/memory.c | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-)
mm/memory.c +12 -1
@@ -3344,7 +3344,7 @@ int in_gate_area_no_task(unsigned long addr)#endif /* __HAVE_ARCH_GATE_AREA */ -static int follow_pte (struct mm_struct *mm,unsigned long address, +static int __follow_pte (struct mm_struct *mm,unsigned long address,pte_t **ptepp,spinlock_t **ptlp) {pgd_t *pgd;
@@ -3381,6 +3381,17 @@ out:return -EINVAL ; } +static inline int follow_pte (struct mm_struct *mm,unsigned long address, +pte_t **ptepp,spinlock_t **ptlp) +{ +int res; + +/* (void) is needed to make gcc happy */ + (void )__cond_lock (*ptlp, + !(res =__follow_pte (mm, address, ptepp, ptlp))); +return res; +} +/** * follow_pfn - look up PFN at a user virtual address * @vma: memory mapping
Signature · 7 lines
1.7.2.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 6/12 rmap: annotate lock context change on page_[un]lock_anon_vma()
In reply to Namhyung KimThe page_lock_anon_vma() conditionally grabs RCU and anon_vma lock but page_unlock_anon_vma() releases them unconditionally. This leads sparse to complain about context imbalance. Annotate them.
--- include/linux/rmap.h | 15 ++++++++++++++- mm/rmap.c | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-)
include/linux/rmap.h +14 -1
@@ -230,7 +230,20 @@ int try_to_munlock(struct page *);/* * Called by memory-failure.c to kill processes. */ -struct anon_vma *page_lock_anon_vma (struct page *page); +struct anon_vma *__page_lock_anon_vma (struct page *page); + +static inline struct anon_vma *page_lock_anon_vma (struct page *page) +{ +struct anon_vma *anon_vma; + +__cond_lock (RCU , anon_vma =__page_lock_anon_vma (page)); + +/* (void) is needed to make gcc happy */ + (void )__cond_lock (&anon_vma->root->lock, anon_vma); + +return anon_vma; +} +void page_unlock_anon_vma (struct anon_vma *anon_vma);int page_mapped_in_vma (struct page *page,struct vm_area_struct *vma);
mm/rmap.c +3 -1
@@ -314,7 +314,7 @@ void __init anon_vma_init(void)* Getting a lock on a stable anon_vma from a page off the LRU is * tricky: page_lock_anon_vma rely on RCU to guard against the races. */ -struct anon_vma *page_lock_anon_vma (struct page *page) +struct anon_vma *__page_lock_anon_vma (struct page *page) {struct anon_vma *anon_vma, *root_anon_vma;unsigned long anon_mapping;
@@ -348,6 +348,8 @@ out: }void page_unlock_anon_vma (struct anon_vma *anon_vma) + __releases(&anon_vma->root->lock) +__releases (RCU ) {anon_vma_unlock (anon_vma);rcu_read_unlock ();
Signature · 7 lines
1.7.2.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 7/12 rmap: wrap page_check_address() using __cond_lock()
In reply to Namhyung KimThe page_check_address() conditionally grabs *@ptlp in case of returning non-NULL. Rename and wrap it using __cond_lock() removes following warnings from sparse:
mm/rmap.c:472:9: warning: context imbalance in 'page_mapped_in_vma' - unexpected unlock mm/rmap.c:524:9: warning: context imbalance in 'page_referenced_one' - unexpected unlock mm/rmap.c:706:9: warning: context imbalance in 'page_mkclean_one' - unexpected unlock mm/rmap.c:1066:9: warning: context imbalance in 'try_to_unmap_one' - unexpected unlock
--- include/linux/rmap.h | 13 ++++++++++++- mm/rmap.c | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-)
include/linux/rmap.h +12 -1
@@ -205,9 +205,20 @@ int try_to_unmap_one(struct page *, struct vm_area_struct *,/* * Called from mm/filemap_xip.c to unmap empty zero page */ -pte_t *page_check_address (struct page *,struct mm_struct *, +pte_t *__page_check_address (struct page *,struct mm_struct *,unsigned long ,spinlock_t **,int ); +static inline pte_t *page_check_address (struct page *page,struct mm_struct *mm, +unsigned long address, +spinlock_t **ptlp,int sync) +{ +pte_t *ptep; + +__cond_lock (*ptlp, ptep =__page_check_address (page, mm, address, + ptlp, sync)); +return ptep; +} +/* * Used by swapoff to help locate where page is expected in vma. */
mm/rmap.c +1 -1
@@ -403,7 +403,7 @@ unsigned long page_address_in_vma(struct page *page, struct vm_area_struct *vma)* * On success returns with pte mapped and locked. */ -pte_t *page_check_address (struct page *page,struct mm_struct *mm, +pte_t *__page_check_address (struct page *page,struct mm_struct *mm,unsigned long address,spinlock_t **ptlp,int sync) {pgd_t *pgd;
Signature · 7 lines
1.7.2.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 8/12 rmap: make anon_vma_[chain_]free() static
In reply to Namhyung KimMake anon_vma_free() and anon_vma_chain_free() static. They are called only in rmap.c and corresponding alloc functions are already static.
--- include/linux/rmap.h | 1 - mm/rmap.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-)
include/linux/rmap.h +0 -1
@@ -148,7 +148,6 @@ void unlink_anon_vmas(struct vm_area_struct *);int anon_vma_clone (struct vm_area_struct *,struct vm_area_struct *);int anon_vma_fork (struct vm_area_struct *,struct vm_area_struct *);void __anon_vma_link (struct vm_area_struct *); -void anon_vma_free (struct anon_vma *);static inline void anon_vma_merge (struct vm_area_struct *vma,struct vm_area_struct *next)
mm/rmap.c +2 -2
@@ -70,7 +70,7 @@ static inline struct anon_vma *anon_vma_alloc(void)return kmem_cache_alloc (anon_vma_cachep,GFP_KERNEL ); } -void anon_vma_free (struct anon_vma *anon_vma) +static void anon_vma_free (struct anon_vma *anon_vma) {kmem_cache_free (anon_vma_cachep, anon_vma); }
@@ -80,7 +80,7 @@ static inline struct anon_vma_chain *anon_vma_chain_alloc(void)return kmem_cache_alloc (anon_vma_chain_cachep,GFP_KERNEL ); } -void anon_vma_chain_free (struct anon_vma_chain *anon_vma_chain) +static void anon_vma_chain_free (struct anon_vma_chain *anon_vma_chain) {kmem_cache_free (anon_vma_chain_cachep, anon_vma_chain); }
Signature · 7 lines
1.7.2.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 9/12 vmalloc: rename temporary variable in __insert_vmap_area()
In reply to Namhyung KimRename redundant 'tmp' to fix following sparse warnings:
mm/vmalloc.c:296:34: warning: symbol 'tmp' shadows an earlier one mm/vmalloc.c:293:24: originally declared here
--- mm/vmalloc.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
mm/vmalloc.c +4 -4
@@ -293,13 +293,13 @@ static void __insert_vmap_area(struct vmap_area *va)struct rb_node *tmp;while (*p) { -struct vmap_area *tmp; +struct vmap_area *tmp_va; parent = *p; - tmp = rb_entry(parent, struct vmap_area, rb_node); -if (va->va_start < tmp->va_end) + tmp_va = rb_entry(parent, struct vmap_area, rb_node); +if (va->va_start < tmp_va->va_end) p = &(*p)->rb_left; -else if (va->va_end > tmp->va_start) +else if (va->va_end > tmp_va->va_start) p = &(*p)->rb_right;else BUG ();
Signature · 7 lines
1.7.2.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 10/12 vmalloc: annotate lock context change on s_start/stop()
In reply to Namhyung Kims_start() and s_stop() grab/release vmlist_lock but were missing proper annotations. Add them.
--- mm/vmalloc.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
mm/vmalloc.c +2 -0
@@ -2339,6 +2339,7 @@ void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)#ifdef CONFIG_PROC_FS static void *s_start (struct seq_file *m,loff_t *pos) + __acquires(&vmlist_lock) {loff_t n = *pos;struct vm_struct *v;
@@ -2365,6 +2366,7 @@ static void *s_next(struct seq_file *m, void *p, loff_t *pos) }static void s_stop (struct seq_file *m,void *p) + __releases(&vmlist_lock) {read_unlock (&vmlist_lock); }
Signature · 7 lines
1.7.2.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 11/12 mm: declare some external symbols
In reply to Namhyung KimDeclare 'bdi_pending_list' and 'tag_pages_for_writeback()' to remove following sparse warnings:
mm/backing-dev.c:46:1: warning: symbol 'bdi_pending_list' was not declared. Should it be static? mm/page-writeback.c:825:6: warning: symbol 'tag_pages_for_writeback' was not declared. Should it be static?
--- include/linux/backing-dev.h | 1 + include/linux/writeback.h | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-)
include/linux/backing-dev.h +1 -0
@@ -111,6 +111,7 @@ void bdi_wakeup_thread_delayed(struct backing_dev_info *bdi);extern spinlock_t bdi_lock;extern struct list_head bdi_list; +extern struct list_head bdi_pending_list;static inline int wb_has_dirty_io (struct bdi_writeback *wb) {
include/linux/writeback.h +2 -0
@@ -149,6 +149,8 @@ int write_cache_pages(struct address_space *mapping,int do_writepages (struct address_space *mapping,struct writeback_control *wbc);void set_page_dirty_balance (struct page *page,int page_mkwrite);void writeback_set_ratelimit (void ); +void tag_pages_for_writeback (struct address_space *mapping, +pgoff_t start,pgoff_t end);/* pdflush.c */ extern int nr_pdflush_threads;/* Global so it can be exported to sysctl
Signature · 7 lines
1.7.2.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 12/12 vmstat: include compaction.h when CONFIG_COMPACTION
In reply to Namhyung KimThis removes following warning from sparse:
mm/vmstat.c:466:5: warning: symbol 'fragmentation_index' was not declared. Should it be static?
--- mm/vmstat.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
mm/vmstat.c +2 -0
@@ -394,6 +394,8 @@ void zone_statistics(struct zone *preferred_zone, struct zone *z)#endif #ifdef CONFIG_COMPACTION +#include <linux/compaction.h> + struct contig_page_info { unsigned long free_pages; unsigned long free_blocks_total;
Signature · 7 lines
1.7.2.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH 12/12] vmstat: include compaction.h when CONFIG_COMPACTION
Some of these patches do make the code significantly more complex to read and follow. Boy, I hope it's all useful!
Quoted 14 lines · On Thu, 30 Sep 2010 12:50:21 +0900 Namhyung Kim <[email protected]> wrote:
This removes following warning from sparse:
mm/vmstat.c:466:5: warning: symbol 'fragmentation_index' was not declared. Should it be static?Signed-off-by Namhyung Kim <[email protected]>--- mm/vmstat.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)mm/vmstat.c +0
-0
mm/vmstat.c void zone_statistics(struct zone *preferred_zone, struct zone *z) · line 401
Quoted 8 lines
mm/vmstat.c +2
-0@@ -394,6 +394,8 @@ void zone_statistics(struct zone *preferred_zone, struct zone *z)#endif #ifdef CONFIG_COMPACTION +#include <linux/compaction.h> + struct contig_page_info { unsigned long free_pages; unsigned long free_blocks_total;
This isn't a good idea: there's a good chance that someone will later add a #include <linux/compaction.h> at the top of the file to support future changes. So we end up including it twice.
So I assume the below will work OK??
mm/vmstat.c renamed from mm/vmstat.c~vmstat-include-compactionh-when-config_compaction-fix +1 -1
@@ -18,6 +18,7 @@#include <linux/sched.h> #include <linux/math64.h> #include <linux/writeback.h> +#include <linux/compaction.h> #ifdef CONFIG_VM_EVENT_COUNTERS DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}};
@@ -395,7 +396,6 @@ void zone_statistics(struct zone *prefer#endif #ifdef CONFIG_COMPACTION -#include <linux/compaction.h> struct contig_page_info { unsigned long free_pages;
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>