[bug report] proc: rewrite stable_page_flags()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Matthew Wilcox (Oracle),

Commit ea1be2228bb6 ("proc: rewrite stable_page_flags()") from Mar
26, 2024 (linux-next), leads to the following Smatch static checker
warning:

fs/proc/page.c:156 stable_page_flags() warn: bit shifter 'PG_lru' used for logical '&'
fs/proc/page.c:207 stable_page_flags() warn: bit shifter 'KPF_HUGE' used for logical '&'

fs/proc/page.c
    110 u64 stable_page_flags(const struct page *page)
    111 {
    112         const struct folio *folio;
    113         unsigned long k;
    114         unsigned long mapping;
    115         bool is_anon;
    116         u64 u = 0;
    117 
    118         /*
    119          * pseudo flag: KPF_NOPAGE
    120          * it differentiates a memory hole from a page with no flags
    121          */
    122         if (!page)
    123                 return 1 << KPF_NOPAGE;
    124         folio = page_folio(page);
    125 
    126         k = folio->flags;
    127         mapping = (unsigned long)folio->mapping;
    128         is_anon = mapping & PAGE_MAPPING_ANON;
    129 
    130         /*
    131          * pseudo flags for the well known (anonymous) memory mapped pages
    132          */
    133         if (page_mapped(page))
    134                 u |= 1 << KPF_MMAP;
    135         if (is_anon) {
    136                 u |= 1 << KPF_ANON;
    137                 if (mapping & PAGE_MAPPING_KSM)
    138                         u |= 1 << KPF_KSM;
    139         }
    140 
    141         /*
    142          * compound pages: export both head/tail info
    143          * they together define a compound page's start/end pos and order
    144          */
    145         if (page == &folio->page)
    146                 u |= kpf_copy_bit(k, KPF_COMPOUND_HEAD, PG_head);
    147         else
    148                 u |= 1 << KPF_COMPOUND_TAIL;
    149         if (folio_test_hugetlb(folio))
    150                 u |= 1 << KPF_HUGE;
                             ^^^^^^^^^^^^^
Here KPF_HUGE is a shifter

    151         /*
    152          * We need to check PageLRU/PageAnon
    153          * to make sure a given page is a thp, not a non-huge compound page.
    154          */
    155         else if (folio_test_large(folio)) {
--> 156                 if ((k & PG_lru) || is_anon)
                             ^^^^^^^^^^
The PG_lru enum isn't used consistently.  Should this be?:

	if ((k & (1 << PG_lru)) || ...


    157                         u |= 1 << KPF_THP;
    158                 else if (is_huge_zero_folio(folio)) {
    159                         u |= 1 << KPF_ZERO_PAGE;
    160                         u |= 1 << KPF_THP;
    161                 }
    162         } else if (is_zero_pfn(page_to_pfn(page)))
    163                 u |= 1 << KPF_ZERO_PAGE;
    164 
    165         /*
    166          * Caveats on high order pages: PG_buddy and PG_slab will only be set
    167          * on the head page.
    168          */
    169         if (PageBuddy(page))
    170                 u |= 1 << KPF_BUDDY;
    171         else if (page_count(page) == 0 && is_free_buddy_page(page))
    172                 u |= 1 << KPF_BUDDY;
    173 
    174         if (PageOffline(page))
    175                 u |= 1 << KPF_OFFLINE;
    176         if (PageTable(page))
    177                 u |= 1 << KPF_PGTABLE;
    178 
    179 #if defined(CONFIG_PAGE_IDLE_FLAG) && defined(CONFIG_64BIT)
    180         u |= kpf_copy_bit(k, KPF_IDLE,          PG_idle);
    181 #else
    182         if (folio_test_idle(folio))
    183                 u |= 1 << KPF_IDLE;
    184 #endif
    185 
    186         u |= kpf_copy_bit(k, KPF_LOCKED,        PG_locked);
    187         u |= kpf_copy_bit(k, KPF_SLAB,                PG_slab);
    188         u |= kpf_copy_bit(k, KPF_ERROR,                PG_error);
    189         u |= kpf_copy_bit(k, KPF_DIRTY,                PG_dirty);
    190         u |= kpf_copy_bit(k, KPF_UPTODATE,        PG_uptodate);
    191         u |= kpf_copy_bit(k, KPF_WRITEBACK,        PG_writeback);
    192 
    193         u |= kpf_copy_bit(k, KPF_LRU,                PG_lru);
    194         u |= kpf_copy_bit(k, KPF_REFERENCED,        PG_referenced);
    195         u |= kpf_copy_bit(k, KPF_ACTIVE,        PG_active);
    196         u |= kpf_copy_bit(k, KPF_RECLAIM,        PG_reclaim);
    197 
    198 #define SWAPCACHE ((1 << PG_swapbacked) | (1 << PG_swapcache))
    199         if ((k & SWAPCACHE) == SWAPCACHE)
    200                 u |= 1 << KPF_SWAPCACHE;
    201         u |= kpf_copy_bit(k, KPF_SWAPBACKED,        PG_swapbacked);
    202 
    203         u |= kpf_copy_bit(k, KPF_UNEVICTABLE,        PG_unevictable);
    204         u |= kpf_copy_bit(k, KPF_MLOCKED,        PG_mlocked);
    205 
    206 #ifdef CONFIG_MEMORY_FAILURE
    207         if (u & KPF_HUGE)
                    ^^^^^^^^^^^^
Here it is a mask.

    208                 u |= kpf_copy_bit(k, KPF_HWPOISON,        PG_hwpoison);
    209         else
    210                 u |= kpf_copy_bit(page->flags, KPF_HWPOISON,        PG_hwpoison);
    211 #endif
    212 
    213 #ifdef CONFIG_ARCH_USES_PG_UNCACHED
    214         u |= kpf_copy_bit(k, KPF_UNCACHED,        PG_uncached);
    215 #endif
    216 
    217         u |= kpf_copy_bit(k, KPF_RESERVED,        PG_reserved);
    218         u |= kpf_copy_bit(k, KPF_MAPPEDTODISK,        PG_mappedtodisk);
    219         u |= kpf_copy_bit(k, KPF_PRIVATE,        PG_private);
    220         u |= kpf_copy_bit(k, KPF_PRIVATE_2,        PG_private_2);
    221         u |= kpf_copy_bit(k, KPF_OWNER_PRIVATE,        PG_owner_priv_1);
    222         u |= kpf_copy_bit(k, KPF_ARCH,                PG_arch_1);
    223 #ifdef CONFIG_ARCH_USES_PG_ARCH_X
    224         u |= kpf_copy_bit(k, KPF_ARCH_2,        PG_arch_2);
    225         u |= kpf_copy_bit(k, KPF_ARCH_3,        PG_arch_3);
    226 #endif
    227 
    228         return u;
    229 };

regards,
dan carpenter




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux