user1734905
user1734905

Reputation: 333

Kernel threads accessing user space address

here's a quote from Understand Linux kernel book (emphasis mine)

... no need to invalidate a TLB entry that refers to a User Mode linear address, because no kernel thread accesses the User Mode address space

I understand the user space process cannot access kernel space, but why the reverse (which is what i think the sentence above implies) true? Is this enforced by hardware, or simply a design choice of the kernel?

Upvotes: 0

Views: 926

Answers (1)

user4822941
user4822941

Reputation:

The sentence is wrong, but in the context it is fine enough.

The full quote is:

In fact, each kernel thread does not have its own set of page tables; rather, it makes use of the set of page tables belonging to a regular process. However, there is no need to invalidate a TLB entry that refers to a User Mode linear address, because no kernel thread accesses the User Mode address space

What they mean is switching user <-> user thread changes address spaces (duh), but user thread -> kernel thread and kernel thread -> kernel thread DOES NOT as an optimisation. kernel threads are not tied to any user thread, so there is no specific user part of the address space to access in the first place. As things get scheduled in different order over time and a particular kernel thread gets executed after random user threads, it keeps executing with different page tables for the user part (kernel part stays the same). So there is nothing for a kernel thread to access in userspace. Just do ps auxw and check all the stuff with enclosed in '[]'. That's kernel threads.

This must not be confused with kernel code accessing userspace - this happens all the time, e.g. when a user thread performs a syscall.

I also said the sentence is wrong because in special cases a kernel thread can explicitly set a particular address space for use. This is done by aio.

Upvotes: 1

Related Questions