1

I have a question regarding the way proc files are handled when several instances of the same driver are running simultaneously. lets assume that a my system runs a couple of instances of the same driver simultaneously, but only one of them (according to some inner decision making) created a proc file and maintains the information that should be written when the file is being read. since all of the instances are of the same driver, they all contain the function that will be invoked when the proc file is being read (though this function is actually registered only by one of the instances). My question is: when the kernel invokes the read function, will it always invoke the function from the address space of the module that created the proc file, or could it call it from the address space of another instance?

omer
  • 1,242
  • 4
  • 18
  • 45

1 Answers1

2

You cannot load several instances of the same driver. The second loading of the same driver will be refused because of drivers' names collision.

Another reason why you situation is unreachable: creating proc file with name which corresponds to already existing file will fail.

Update (as question became more specific)

Kernel doesn't check addresses, passed to it from modules. It just uses these addresses, e.g., calls function.

As for address space of different modules, all modules share same address space with the kernel core. So, any address (e.g. address of the read function for 'proc' file) may belong to at most one module (or kernel core). When module is loaded into kernel, kernel allocates memory for its code and static data. When module is unloaded, memory with its code and data is freed.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • You can do this, but give it a different name or a suffix, such as mod_0, mod_1, etc.. but then i guess this is enough for the kernel to distinguish the specific module that created the proc file. – omer Aug 10 '15 at 19:50
  • I can ask a bit different question: when calling to _italic_create_proc_read_entry() you must supply a function that will be invoked when your proc file is being read. does the kernel simply register this function as the read function for this file, regardless of the module it resides in and whether or not this module is loaded (ignore the fact that if the module is unloaded the proc entry should be removed)? – omer Aug 10 '15 at 20:56
  • 1
    Oh, you better edit you current question to content this one. But answer is simple: kernel doesn't check, which module defines function passed to it. All modules and kernel core itself are placed withing same address space and can do anything. – Tsyvarev Aug 10 '15 at 21:56
  • Thanks for the comment, i edited the question. Now, another thing - as you said, the kernel doesn't check which module registered the function, it just invokes the function automatically when the file is being read. Now, since a function is merely a location in memory. If a driver is loaded several times, will this function appear several times in memory? if so, will the kernel invoke the function of the specific instance that created the proc file? – omer Aug 11 '15 at 07:41
  • 1
    I added note about kernel address space into my answer. `If a driver is loaded several times, will this function appear several times in memory?` - Yes, several instances of function will appear in the memory, but each one with its own address. Kernel will use function, which address is passed to `create_proc_read_entry()` call. – Tsyvarev Aug 11 '15 at 17:59
  • Thanks a lot @Tsyvarev – omer Aug 12 '15 at 06:19