Skip to content

Commit 2571873

Browse files
Andi KleenAndi Kleen
authored andcommitted
HWPOISON: Define a new error_remove_page address space op for async truncation
Truncating metadata pages is not safe right now before we haven't audited all file systems. To enable truncation only for data address space define a new address_space callback error_remove_page. This is used for memory_failure.c memory error handling. This can be then set to truncate_inode_page() This patch just defines the new operation and adds documentation. Callers and users come in followon patches. Signed-off-by: Andi Kleen <[email protected]>
1 parent 83f7866 commit 2571873

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

Documentation/filesystems/vfs.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ struct address_space_operations {
536536
/* migrate the contents of a page to the specified target */
537537
int (*migratepage) (struct page *, struct page *);
538538
int (*launder_page) (struct page *);
539+
int (*error_remove_page) (struct mapping *mapping, struct page *page);
539540
};
540541

541542
writepage: called by the VM to write a dirty page to backing store.
@@ -694,6 +695,12 @@ struct address_space_operations {
694695
prevent redirtying the page, it is kept locked during the whole
695696
operation.
696697

698+
error_remove_page: normally set to generic_error_remove_page if truncation
699+
is ok for this address space. Used for memory failure handling.
700+
Setting this implies you deal with pages going away under you,
701+
unless you have them locked or reference counts increased.
702+
703+
697704
The File Object
698705
===============
699706

include/linux/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ struct address_space_operations {
595595
int (*launder_page) (struct page *);
596596
int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
597597
unsigned long);
598+
int (*error_remove_page)(struct address_space *, struct page *);
598599
};
599600

600601
/*

include/linux/mm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ extern int vmtruncate(struct inode * inode, loff_t offset);
795795
extern int vmtruncate_range(struct inode * inode, loff_t offset, loff_t end);
796796

797797
int truncate_inode_page(struct address_space *mapping, struct page *page);
798+
int generic_error_remove_page(struct address_space *mapping, struct page *page);
798799

799800
int invalidate_inode_page(struct page *page);
800801

mm/truncate.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,23 @@ int truncate_inode_page(struct address_space *mapping, struct page *page)
146146
return truncate_complete_page(mapping, page);
147147
}
148148

149+
/*
150+
* Used to get rid of pages on hardware memory corruption.
151+
*/
152+
int generic_error_remove_page(struct address_space *mapping, struct page *page)
153+
{
154+
if (!mapping)
155+
return -EINVAL;
156+
/*
157+
* Only punch for normal data pages for now.
158+
* Handling other types like directories would need more auditing.
159+
*/
160+
if (!S_ISREG(mapping->host->i_mode))
161+
return -EIO;
162+
return truncate_inode_page(mapping, page);
163+
}
164+
EXPORT_SYMBOL(generic_error_remove_page);
165+
149166
/*
150167
* Safely invalidate one page from its pagecache mapping.
151168
* It only drops clean, unused pages. The page must be locked.

0 commit comments

Comments
 (0)