]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mm,fs: split dump_mapping() out from dump_page()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 14 Jan 2022 22:05:04 +0000 (14:05 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 15 Jan 2022 14:30:26 +0000 (16:30 +0200)
dump_mapping() is a big chunk of dump_page(), and it'd be handy to be
able to call it when we don't have a struct page.  Split it out and move
it to fs/inode.c.  Take the opportunity to simplify some of the debug
messages a little.

Link: https://lkml.kernel.org/r/20211121121056.2870061-1-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/inode.c
include/linux/fs.h
mm/debug.c

index 6b80a51129d56f4175326e1faf1429e4f730f8b9..980e7b7a546077af6a79639889d85b0bcf95fc27 100644 (file)
@@ -526,6 +526,55 @@ void __remove_inode_hash(struct inode *inode)
 }
 EXPORT_SYMBOL(__remove_inode_hash);
 
+void dump_mapping(const struct address_space *mapping)
+{
+       struct inode *host;
+       const struct address_space_operations *a_ops;
+       struct hlist_node *dentry_first;
+       struct dentry *dentry_ptr;
+       struct dentry dentry;
+       unsigned long ino;
+
+       /*
+        * If mapping is an invalid pointer, we don't want to crash
+        * accessing it, so probe everything depending on it carefully.
+        */
+       if (get_kernel_nofault(host, &mapping->host) ||
+           get_kernel_nofault(a_ops, &mapping->a_ops)) {
+               pr_warn("invalid mapping:%px\n", mapping);
+               return;
+       }
+
+       if (!host) {
+               pr_warn("aops:%ps\n", a_ops);
+               return;
+       }
+
+       if (get_kernel_nofault(dentry_first, &host->i_dentry.first) ||
+           get_kernel_nofault(ino, &host->i_ino)) {
+               pr_warn("aops:%ps invalid inode:%px\n", a_ops, host);
+               return;
+       }
+
+       if (!dentry_first) {
+               pr_warn("aops:%ps ino:%lx\n", a_ops, ino);
+               return;
+       }
+
+       dentry_ptr = container_of(dentry_first, struct dentry, d_u.d_alias);
+       if (get_kernel_nofault(dentry, dentry_ptr)) {
+               pr_warn("aops:%ps ino:%lx invalid dentry:%px\n",
+                               a_ops, ino, dentry_ptr);
+               return;
+       }
+
+       /*
+        * if dentry is corrupted, the %pd handler may still crash,
+        * but it's unlikely that we reach here with a corrupt mapping
+        */
+       pr_warn("aops:%ps ino:%lx dentry name:\"%pd\"\n", a_ops, ino, &dentry);
+}
+
 void clear_inode(struct inode *inode)
 {
        /*
index bbf812ce89a8c0739cb2e69716183273b69b2573..5315fa68f751a71ca56d90cbcde659ce8cbaf4f7 100644 (file)
@@ -3152,6 +3152,7 @@ extern void unlock_new_inode(struct inode *);
 extern void discard_new_inode(struct inode *);
 extern unsigned int get_next_ino(void);
 extern void evict_inodes(struct super_block *sb);
+void dump_mapping(const struct address_space *);
 
 /*
  * Userspace may rely on the the inode number being non-zero. For example, glibc
index a05a39ff8fe4f676a38b542dfc14c177369be5c8..bc9ac87f0e08d01a9a3bf7748fd3d3f90d6bd013 100644 (file)
@@ -112,56 +112,8 @@ static void __dump_page(struct page *page)
                type = "ksm ";
        else if (PageAnon(page))
                type = "anon ";
-       else if (mapping) {
-               struct inode *host;
-               const struct address_space_operations *a_ops;
-               struct hlist_node *dentry_first;
-               struct dentry *dentry_ptr;
-               struct dentry dentry;
-               unsigned long ino;
-
-               /*
-                * mapping can be invalid pointer and we don't want to crash
-                * accessing it, so probe everything depending on it carefully
-                */
-               if (get_kernel_nofault(host, &mapping->host) ||
-                   get_kernel_nofault(a_ops, &mapping->a_ops)) {
-                       pr_warn("failed to read mapping contents, not a valid kernel address?\n");
-                       goto out_mapping;
-               }
-
-               if (!host) {
-                       pr_warn("aops:%ps\n", a_ops);
-                       goto out_mapping;
-               }
-
-               if (get_kernel_nofault(dentry_first, &host->i_dentry.first) ||
-                   get_kernel_nofault(ino, &host->i_ino)) {
-                       pr_warn("aops:%ps with invalid host inode %px\n",
-                                       a_ops, host);
-                       goto out_mapping;
-               }
-
-               if (!dentry_first) {
-                       pr_warn("aops:%ps ino:%lx\n", a_ops, ino);
-                       goto out_mapping;
-               }
-
-               dentry_ptr = container_of(dentry_first, struct dentry, d_u.d_alias);
-               if (get_kernel_nofault(dentry, dentry_ptr)) {
-                       pr_warn("aops:%ps ino:%lx with invalid dentry %px\n",
-                                       a_ops, ino, dentry_ptr);
-               } else {
-                       /*
-                        * if dentry is corrupted, the %pd handler may still
-                        * crash, but it's unlikely that we reach here with a
-                        * corrupted struct page
-                        */
-                       pr_warn("aops:%ps ino:%lx dentry name:\"%pd\"\n",
-                                       a_ops, ino, &dentry);
-               }
-       }
-out_mapping:
+       else if (mapping)
+               dump_mapping(mapping);
        BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS + 1);
 
        pr_warn("%sflags: %pGp%s\n", type, &head->flags,