title: Why is this kernel module marked at permanent on 2.6.39
body: <p>When I load this module:</p>
  
  <pre><code>#include &lt;linux/init.h&gt;
  #include &lt;linux/module.h&gt;
  #include &lt;linux/kernel.h&gt;
  
  MODULE_LICENSE("Dual BSD/GPL");
  
  static int hello_init(void) {
    printk("&lt;1&gt; Hello world!\n");
    return 0;
  }
  
  static void hello_exit(void) {
    printk("&lt;1&gt; Bye, cruel world\n");
  }
  
  
  module_init(hello_init);
  module_exit(hello_exit);
  </code></pre>
  
  <p>(From <a href="http://www.freesoftwaremagazine.com/articles/drivers_linux?page=0,2" rel="noreferrer">http://www.freesoftwaremagazine.com/articles/drivers_linux?page=0,2</a> )</p>
  
  <p>The module get marked as <code>[permanent]</code> in <code>lsmod</code> and can't be unloaded, on 2.6.39-02063904-generic (from the <a href="http://kernel.ubuntu.com/~kernel-ppa/mainline/v2.6.39.4-oneiric/" rel="noreferrer">Ubuntu PPA</a>). But it works fine on the default 2.6.38 kernel. (Both on Ubuntu 11.04 x86).</p>
  
  <p>What has changed in 2.6.39? and what do I need to change in my code?</p>
  
  <p>I was trying to isolate a more complicated problem when I ran into this issue.</p>
  
  <p>EDIT:</p>
  
  <p>Following a suggestion from an answer I edited the code to add <code>__init</code> and <code>__exit</code> (hello3.c):</p>
  
  <pre><code>#include &lt;linux/init.h&gt;
  #include &lt;linux/module.h&gt;
  #include &lt;linux/kernel.h&gt;
  
  MODULE_LICENSE("Dual BSD/GPL");
  
  static int __init hello_init(void) {
    printk("&lt;1&gt; Hello world!\n");
    return 0;
  }
  
  static void __exit hello_exit(void) {
    printk("&lt;1&gt; Bye, cruel world\n");
  }
  
  module_init(hello_init);
  module_exit(hello_exit);
  </code></pre>
  
  <p>The build output:</p>
  
  <pre><code>make -C /lib/modules/2.6.39-02063904-generic/build M=/home/douglas/kernelmod modules
  make[1]: Entering directory `/usr/src/linux-headers-2.6.39-02063904-generic'
  Building with KERNELRELEASE = 2.6.39-02063904-generic
    CC [M]  /home/douglas/kernelmod/hello3.o
    Building modules, stage 2.
  Building with KERNELRELEASE = 2.6.39-02063904-generic
    MODPOST 8 modules
    CC      /home/douglas/kernelmod/hello3.mod.o
    LD [M]  /home/douglas/kernelmod/hello3.ko
  make[1]: Leaving directory `/usr/src/linux-headers-2.6.39-02063904-generic'
  </code></pre>
  
  <p>EDIT2:</p>
  
  <p>hello3.mod.c:</p>
  
  <pre><code>#include &lt;linux/module.h&gt;
  #include &lt;linux/vermagic.h&gt;
  #include &lt;linux/compiler.h&gt;
  
  MODULE_INFO(vermagic, VERMAGIC_STRING);
  
  struct module __this_module
  __attribute__((section(".gnu.linkonce.this_module"))) = {
   .name = KBUILD_MODNAME,
   .init = init_module,
  #ifdef CONFIG_MODULE_UNLOAD
   .exit = cleanup_module,
  #endif
   .arch = MODULE_ARCH_INIT,
  };
  
  static const struct modversion_info ____versions[]
  __used
  __attribute__((section("__versions"))) = {
      { 0xbe4b3e92, "module_layout" },
      { 0xb4390f9a, "mcount" },
      { 0x5e3b3ab4, "printk" },
  };
  
  static const char __module_depends[]
  __used
  __attribute__((section(".modinfo"))) =
  "depends=";
  
  
  MODULE_INFO(srcversion, "D2A869459874C22AB265981");
  </code></pre>
  
  <p>Also </p>
  
  <pre><code># grep CONFIG_MODULE_UNLOAD /boot/config-2.6.39-02063904-generic 
  CONFIG_MODULE_UNLOAD=y
  </code></pre>
  
  <p>EDIT3:</p>
  
  <p>More interestingly it doesn't happen with a vanilla kernel I've compiled myself - that 
  loads and unloads modules fine.</p>
  
  <p>EDIT4:</p>
  
  <p>I installed the Oneiric beta 2 build on a VM, and that 3.0.0-11 kernel doesn't have any problem either. So it appears to be limited to the Ubuntu Vanilla PPA kernels. That won't be much fun to resolve.</p>