mm: allow page_cache_get_speculative in interrupt context
PATCH 1/1 mm: allow page_cache_get_speculative in interrupt context
From: Kan Liang <[email protected]>
Kernel panic when calling the IRQ-safe __get_user_pages_fast in NMI
handler.
The bug was introduced by commit:
2947ba054a4d ("x86/mm/gup: Switch GUP to the genericget_user_page_fast() implementation")
The original x86 __get_user_page_fast used plain get_page() or page_ref_add(). However, the generic __get_user_page_fast uses page_cache_get_speculative(), which has VM_BUG_ON(in_interrupt()).
There is no reason to prevent page_cache_get_speculative from using in interrupt context. According to the author, putting a BUG_ON there is just because the code is not verifying correctness of interrupt races. I did some tests in interrupt context. There is no issue found. Removing VM_BUG_ON(in_interrupt()) for page_cache_get_speculative().
--- include/linux/pagemap.h | 2 -- 1 file changed, 2 deletions(-)
include/linux/pagemap.h +0 -2
@@ -163,8 +163,6 @@ void release_pages(struct page **pages, int nr, bool cold);*/ static inline int page_cache_get_speculative (struct page *page) { -VM_BUG_ON (in_interrupt ()); -#ifdef CONFIG_TINY_RCU # ifdef CONFIG_PREEMPT_COUNT VM_BUG_ON (!in_atomic () && !irqs_disabled ());
Signature · 1 line
2.4.3
Quoted 12 lines · On Tue, 1 Aug 2017 13:39:06 -0400 [email protected] wrote:
Kernel panic when calling the IRQ-safe __get_user_pages_fast in NMIhandler.
The bug was introduced by commit:
2947ba054a4d("x86/mm/gup: Switch GUP to the genericget_user_page_fast()implementation")The original x86
__get_user_page_fastused plainget_page()orpage_ref_add(). However, the generic__get_user_page_fastusespage_cache_get_speculative(), which has VM_BUG_ON(in_interrupt()).
Quoted 5 lines
There is no reason to prevent
page_cache_get_speculativefrom using in interrupt context. According to the author, putting aBUG_ONthere is just because the code is not verifying correctness of interrupt races. I did some tests in interrupt context. There is no issue found. Removing VM_BUG_ON(in_interrupt()) forpage_cache_get_speculative().
What code calls page_cache_get_speculative() from NMI context?
I'm trying to work out which kernel versions need this fix, but there isn't enough info in the changelog for this. Please don't do that.
Quoted 15 lines · On Tue, 1 Aug 2017 13:39:06 -0400 [email protected] wrote:
Quoted 13 lines
Kernel panic when calling the IRQ-safe __get_user_pages_fast in NMIhandler.
The bug was introduced by commit:
2947ba054a4d("x86/mm/gup: Switch GUP to the genericget_user_page_fast()implementation")The original x86
__get_user_page_fastused plainget_page()orpage_ref_add(). However, the generic__get_user_page_fastusespage_cache_get_speculative(), which has VM_BUG_ON(in_interrupt()).
Quoted 8 lines
Quoted 5 lines
There is no reason to prevent
page_cache_get_speculativefrom using in interrupt context. According to the author, putting aBUG_ONthere is just because the code is not verifying correctness of interrupt races. I did some tests in interrupt context. There is no issue found. Removing VM_BUG_ON(in_interrupt()) forpage_cache_get_speculative().What code calls
page_cache_get_speculative()from NMI context?
The code I'm implementing will call __get_user_page_fast from NMI context. __get_user_page_fast will eventually call page_cache_get_speculative().
Quoted 2 lines
I'm trying to work out which kernel versions need this fix, but there isn't enough info in the changelog for this. Please don't do that.
Sorry for the confusion.
According to the comments, __get_user_page_fast should be IRQ-safe. But it's not. This patch could be used to resolve the inconsistencies between the comments and implementations for now.
The generic __get_user_page_fast was introduced by the commit 2667f50e8b81457fcb4a3dbe6aff3e81ea009e13
mm: introduce a general RCU get_user_pages_fast()
I think the kernel after the commit should be fixed.
Thanks,
Kan
Quoted 32 lines · Kan
Quoted 15 lines · On Tue, 1 Aug 2017 13:39:06 -0400 [email protected] wrote:
Quoted 13 lines
Kernel panic when calling the IRQ-safe __get_user_pages_fast in NMIhandler.
The bug was introduced by commit:
2947ba054a4d("x86/mm/gup: Switch GUP to the genericget_user_page_fast()implementation")The original x86
__get_user_page_fastused plainget_page()orpage_ref_add(). However, the generic__get_user_page_fastusespage_cache_get_speculative(), which has VM_BUG_ON(in_interrupt()).Quoted 8 lines
Quoted 5 lines
There is no reason to prevent
page_cache_get_speculativefrom using in interrupt context. According to the author, putting aBUG_ONthere is just because the code is not verifying correctness of interrupt races. I did some tests in interrupt context. There is no issue found. Removing VM_BUG_ON(in_interrupt()) forpage_cache_get_speculative().What code calls
page_cache_get_speculative()from NMI context?The code I'm implementing will call
__get_user_page_fastfrom NMI context.__get_user_page_fastwill eventually callpage_cache_get_speculative().Quoted 2 lines
I'm trying to work out which kernel versions need this fix, but there isn't enough info in the changelog for this. Please don't do that.
Sorry for the confusion.
Quoted 7 lines
According to the comments,
__get_user_page_fastshould be IRQ-safe. But it's not. This patch could be used to resolve the inconsistencies between the comments and implementations for now.
The generic__get_user_page_fastwas introduced by the commit2667f50e8b81457fcb4a3dbe6aff3e81ea009e13
mm: introduce a general RCUget_user_pages_fast()
I think the kernel after the commit should be fixed.
I don't think so.
It's 2+ year in and nobody stepped onto this until you with your patchset. There is no real reason to get it backported.
Signature · 1 line
Kirill A. Shutemov