0

Why is this assertion in __get_vm_area_node?

static struct vm_struct *__get_vm_area_node(...)
{
    // ...
    BUG_ON(in_interrupt())
    // ...
} 
Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
yash
  • 47
  • 5
  • Because someone put it there :P Have you looked at all? What does `in_interrupt()` do? What code is in `__get_vm_area_node()` that doesn't work from interrupts? – domen Oct 19 '20 at 07:27

1 Answers1

0

I think the commit that introduced that line explains it pretty well:

If __vmalloc is called to allocate memory with GFP_ATOMIC in atomic context, the chain of calls results in __get_vm_area_node allocating memory for vm_struct with GFP_KERNEL, causing the 'sleeping from invalid context' warning. This patch fixes it by passing the gfp flags along so __get_vm_area_node allocates memory for vm_struct with the same flags.

@@ -160,13 +160,15 @@ int map_vm_area(struct vm_struct *area, pgprot_t prot, struct page ***pages)
    return err;
 }
 
-struct vm_struct *__get_vm_area_node(unsigned long size, unsigned long flags,
-               unsigned long start, unsigned long end, int node)
+static struct vm_struct *__get_vm_area_node(unsigned long size, unsigned long flags,
+                       unsigned long start, unsigned long end,
+                       int node, gfp_t gfp_mask)
 {
    struct vm_struct **p, *tmp, *area;
    unsigned long align = 1;
    unsigned long addr;
 
+   BUG_ON(in_interrupt());
    if (flags & VM_IOREMAP) {
        int bit = fls(size);

In short, the following code in that function could sleep, and sleeping is not allowed in interrupt context. The BUG_ON is added to prevent this kind of problem.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128