]> nv-tegra.nvidia Code Review - linux-3.10.git/blobdiff - kernel/extable.c
crypto: tegra-se: fix resourse leak
[linux-3.10.git] / kernel / extable.c
index e136ed8d82ba56ab81283a48fe3d6cfb41c23c79..67460b93b1a1cb8d60294cd90c2972ab97fd80e8 100644 (file)
     along with this program; if not, write to the Free Software
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
+#include <linux/ftrace.h>
+#include <linux/memory.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/init.h>
-#include <linux/ftrace.h>
-#include <asm/uaccess.h>
+
 #include <asm/sections.h>
+#include <asm/uaccess.h>
+
+/*
+ * mutex protecting text section modification (dynamic code patching).
+ * some users need to sleep (allocating memory...) while they hold this lock.
+ *
+ * NOT exported to modules - patching kernel text is a really delicate matter.
+ */
+DEFINE_MUTEX(text_mutex);
 
 extern struct exception_table_entry __start___ex_table[];
 extern struct exception_table_entry __stop___ex_table[];
 
+/* Cleared by build time tools if the table is already sorted. */
+u32 __initdata main_extable_sort_needed = 1;
+
 /* Sort the kernel's built-in exception table */
 void __init sort_main_extable(void)
 {
-       sort_extable(__start___ex_table, __stop___ex_table);
+       if (main_extable_sort_needed) {
+               pr_notice("Sorting __ex_table...\n");
+               sort_extable(__start___ex_table, __stop___ex_table);
+       }
 }
 
 /* Given an address, look for it in the exception tables. */
@@ -41,31 +58,68 @@ const struct exception_table_entry *search_exception_tables(unsigned long addr)
        return e;
 }
 
-__notrace_funcgraph int core_kernel_text(unsigned long addr)
+static inline int init_kernel_text(unsigned long addr)
+{
+       if (addr >= (unsigned long)_sinittext &&
+           addr <= (unsigned long)_einittext)
+               return 1;
+       return 0;
+}
+
+int core_kernel_text(unsigned long addr)
 {
        if (addr >= (unsigned long)_stext &&
            addr <= (unsigned long)_etext)
                return 1;
 
        if (system_state == SYSTEM_BOOTING &&
-           addr >= (unsigned long)_sinittext &&
-           addr <= (unsigned long)_einittext)
+           init_kernel_text(addr))
+               return 1;
+       return 0;
+}
+
+/**
+ * core_kernel_data - tell if addr points to kernel data
+ * @addr: address to test
+ *
+ * Returns true if @addr passed in is from the core kernel data
+ * section.
+ *
+ * Note: On some archs it may return true for core RODATA, and false
+ *  for others. But will always be true for core RW data.
+ */
+int core_kernel_data(unsigned long addr)
+{
+       if (addr >= (unsigned long)_sdata &&
+           addr < (unsigned long)_edata)
                return 1;
        return 0;
 }
 
-__notrace_funcgraph int __kernel_text_address(unsigned long addr)
+int __kernel_text_address(unsigned long addr)
 {
        if (core_kernel_text(addr))
                return 1;
-       return __module_text_address(addr) != NULL;
+       if (is_module_text_address(addr))
+               return 1;
+       /*
+        * There might be init symbols in saved stacktraces.
+        * Give those symbols a chance to be printed in
+        * backtraces (such as lockdep traces).
+        *
+        * Since we are after the module-symbols check, there's
+        * no danger of address overlap:
+        */
+       if (init_kernel_text(addr))
+               return 1;
+       return 0;
 }
 
 int kernel_text_address(unsigned long addr)
 {
        if (core_kernel_text(addr))
                return 1;
-       return module_text_address(addr) != NULL;
+       return is_module_text_address(addr);
 }
 
 /*
@@ -81,5 +135,5 @@ int func_ptr_is_kernel_text(void *ptr)
        addr = (unsigned long) dereference_function_descriptor(ptr);
        if (core_kernel_text(addr))
                return 1;
-       return module_text_address(addr) != NULL;
+       return is_module_text_address(addr);
 }