attr: handle idmapped mounts
[linux-2.6-microblaze.git] / lib / stackdepot.c
index 81c69c0..890dcc2 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include <linux/gfp.h>
+#include <linux/interrupt.h>
 #include <linux/jhash.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
@@ -61,7 +62,7 @@ struct stack_record {
        u32 hash;                       /* Hash in the hastable */
        u32 size;                       /* Number of frames in the stack */
        union handle_parts handle;
-       unsigned long entries[1];       /* Variable-sized array of entries. */
+       unsigned long entries[];        /* Variable-sized array of entries. */
 };
 
 static void *stack_slabs[STACK_ALLOC_MAX_SLABS];
@@ -103,9 +104,8 @@ static bool init_stack_slab(void **prealloc)
 static struct stack_record *depot_alloc_stack(unsigned long *entries, int size,
                u32 hash, void **prealloc, gfp_t alloc_flags)
 {
-       int required_size = offsetof(struct stack_record, entries) +
-               sizeof(unsigned long) * size;
        struct stack_record *stack;
+       size_t required_size = struct_size(stack, entries, size);
 
        required_size = ALIGN(required_size, 1 << STACK_ALLOC_ALIGN);
 
@@ -135,7 +135,7 @@ static struct stack_record *depot_alloc_stack(unsigned long *entries, int size,
        stack->handle.slabindex = depot_index;
        stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN;
        stack->handle.valid = 1;
-       memcpy(stack->entries, entries, size * sizeof(unsigned long));
+       memcpy(stack->entries, entries, flex_array_size(stack, entries, size));
        depot_offset += required_size;
 
        return stack;
@@ -154,8 +154,8 @@ static struct stack_record *stack_table[STACK_HASH_SIZE] = {
 static inline u32 hash_stack(unsigned long *entries, unsigned int size)
 {
        return jhash2((u32 *)entries,
-                              size * sizeof(unsigned long) / sizeof(u32),
-                              STACK_HASH_SEED);
+                     array_size(size,  sizeof(*entries)) / sizeof(u32),
+                     STACK_HASH_SEED);
 }
 
 /* Use our own, non-instrumented version of memcmp().
@@ -202,9 +202,20 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle,
                               unsigned long **entries)
 {
        union handle_parts parts = { .handle = handle };
-       void *slab = stack_slabs[parts.slabindex];
+       void *slab;
        size_t offset = parts.offset << STACK_ALLOC_ALIGN;
-       struct stack_record *stack = slab + offset;
+       struct stack_record *stack;
+
+       *entries = NULL;
+       if (parts.slabindex > depot_index) {
+               WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n",
+                       parts.slabindex, depot_index, handle);
+               return 0;
+       }
+       slab = stack_slabs[parts.slabindex];
+       if (!slab)
+               return 0;
+       stack = slab + offset;
 
        *entries = stack->entries;
        return stack->size;
@@ -305,3 +316,26 @@ fast_exit:
        return retval;
 }
 EXPORT_SYMBOL_GPL(stack_depot_save);
+
+static inline int in_irqentry_text(unsigned long ptr)
+{
+       return (ptr >= (unsigned long)&__irqentry_text_start &&
+               ptr < (unsigned long)&__irqentry_text_end) ||
+               (ptr >= (unsigned long)&__softirqentry_text_start &&
+                ptr < (unsigned long)&__softirqentry_text_end);
+}
+
+unsigned int filter_irq_stacks(unsigned long *entries,
+                                            unsigned int nr_entries)
+{
+       unsigned int i;
+
+       for (i = 0; i < nr_entries; i++) {
+               if (in_irqentry_text(entries[i])) {
+                       /* Include the irqentry function into the stack. */
+                       return i + 1;
+               }
+       }
+       return nr_entries;
+}
+EXPORT_SYMBOL_GPL(filter_irq_stacks);