Skip to contentSkip to conversation

Nice values for kernel modules

DISCUSSION Balbir Singh 8 participants 10 messages Mar 16, 2002

lore
Share & tools
lore
#0 lore raw

In older v2.4 we could directly access current->nice and set it to any value we wanted. This has now been replaced by set_user_nice(). The problem that I face is that task_nice() is not exportted, so my kernel module cannot use it to read the current nice value.

Was there some reason for hiding the nice value from kernel modules?

I have the following solutions

0. I could use the TASK_NICE() macro, but I would like to avoid using it.
1. Export task_nice in ksyms.c
2. Use sys_nice() using a user space disguise.

Comments,
Balbir Singh.

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
http://sports.yahoo.com/

#1 lore raw
Quoted 4 lines · Balbir Singh

0. I could use the TASK_NICE() macro, but I would
like to avoid using it.
1. Export task_nice in ksyms.c
2. Use sys_nice() using a user space disguise.

jump to sys_nice() indirectly via exported sys_call_table[].

Regards,
Tigran

#2 lore raw
Quoted 7 lines · On Sat, 16 Mar 2002 09:51:16 +0000 (GMT), <[email protected]> wrote:
Quoted 4 lines · Balbir Singh

0. I could use the TASK_NICE() macro, but I would
like to avoid using it.
1. Export task_nice in ksyms.c
2. Use sys_nice() using a user space disguise.

jump to sys_nice() indirectly via exported sys_call_table[].

Breaks on ia64 and ppc.

#3 lore raw
Quoted 5 lines · Keith Owens
Quoted 1 line · On Sat, 16 Mar 2002 09:51:16 +0000 (GMT), <[email protected]> wrote:

jump to sys_nice() indirectly via exported sys_call_table[].

Breaks on ia64 and ppc.

Not that I want to encourage this sort of thing, but why would it break on ppc?

Paul.

#4 lore raw
Quoted 10 lines · Paul Mackerras
Quoted 5 lines · Keith Owens
Quoted 1 line · On Sat, 16 Mar 2002 09:51:16 +0000 (GMT), <[email protected]> wrote:

jump to sys_nice() indirectly via exported sys_call_table[].

Breaks on ia64 and ppc.

Not that I want to encourage this sort of thing, but why would it break on ppc?

and also why would it break on ia64. I can understand __mips but why ia64?

Regards
Tigran

#5 lore raw
Quoted 4 lines · Tigran Aivazian
Quoted 2 lines · Paul Mackerras

Keith Owens writes:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 1 line · On Sat, 16 Mar 2002 09:51:16 +0000 (GMT), <[email protected]> wrote:

jump to sys_nice() indirectly via exported sys_call_table[].

Breaks on ia64 and ppc.

Not that I want to encourage this sort of thing, but why would it break on ppc?

Should have been ppc64, not ppc.

Quoted 1 line

and also why would it break on ia64. I can understand __mips but why ia64?

Address of function text is NOT the same as &function. On many architectures &function is the same as the first byte of the function text but not on all architectures. On IA64 &func points to a function descriptor which contains { void * __gp; void * function_text; }. When you call a function on ia64, the code is really :-

save current __gp
load address of function_text
load __gp (global data pointer) for new function call function_text
restore original __gp

Within the kernel, all direct function calls (call function by name) are assumed to have the same __gp so the code reduces to :-

load address of function_text
call function_text

just like most other architectures, this is why syscalls within the kernel work.

When the kernel calls a function via a pointer then __gp must be saved, set and restored. This is especially true when calling from the kernel to a module or vice versa, I guarantee that kernel and modules have different __gp values.

Fetching &sys_nice from the syscall table and blindly calling that address from a module will crash the kernel. PPC64 has a similar problem, it has a function descriptor that contains 3 fields.

There is no architecture independent method for accessing syscall entries _as functions_ from a module. Code that works on ix86 will break on ia64 and ppc64. I can see no good reason why the syscall table has been exported.

#6 lore raw
Quoted 1 line · Keith Owens

I can see no good reason why the syscall table has been exported.

There are lots of good reasons why it has been exported, e.g. ability to replace some system calls while leaving overall Linux personality (i.e. without switching to an ABI emulation).

Ability to bypass the stupid commercial time-locked licences (at some time wordperfect demo was locked like that and my timetravel module turned a demo into full product -- users were happy, at least according to emails I received :)

Also, ability to call those system calls from a module which are not exported individually. Actually, the list of useful possibilities is endless. Wasn't it wine or dosemu (or some other similar software) which was based on being able to access sys_call_table. I can't remember the name of that software but I am sure that a lot of things will break if sys_call_table is unexported.

Anyway, yes, I agree that this feature is mainly useful on i386 architecture. I should have explicitly stated this when I recommended it.

(actually, I didn't _recommend_ it but only listed it as a possiblity.

Quoted 1 line

From the possibilities that were originally listed I would recommend the

macro)

Regards,
Tigran

#8 lore raw
In reply to Keith Owens
Quoted 3 lines · Tigran Aivazian

There are lots of good reasons why it has been exported, e.g. ability to replace some system calls while leaving overall Linux personality (i.e. without switching to an ABI emulation).

No, that never was a good reason and has been removed by Arjan and me in current Linux-ABI versions.

I'm all for removing it, too.

Quoted 2 lines

Also, ability to call those system calls from a module which are not exported individually.

If syscalls are supposed to be used by modules they should be exported and have proper prototypes.

#9 lore raw
In reply to Tigran Aivazian
Quoted 1 line · Keith Owens

I can see no good reason why the syscall table has been exported.

please don't change this. Just because it breaks on architectures X and Y doesn't mean it's useless.

System call snooping is an ugly thing but being able to do it without patching the kernel is incredibly useful. We're not unaware that it is arch-specific.

regards
john

Signature · 2 lines
I am a complete moron for forgetting about endianness. May I be
forever marked as such.
#7 lore raw
In reply to Tigran Aivazian
Quoted 4 lines

Ability to bypass the stupid commercial time-locked licences (at some time wordperfect demo was locked like that and my timetravel module turned a demo into full product -- users were happy, at least according to emails I received :)

Not any more. Under the DMCA your time travel module probably makes you a fugtive from US justice 8)

In general though calling into the syscall table by hand is a bad move. If the function you are calling is generically useful then its much better to work out whether the real function should be exported.