Understanding Linux kernel (https://www.amazon.in/Understanding-Linux-Kernel-Process-Management-ebook/dp/B0043D2E54) mentions the following:
As stated earlier, the Current Privilege Level of the CPU indicates whether the processor is in User or Kernel Mode and is specified by the RPL field of the Segment Selector stored in the cs register. Whenever the CPL is changed, some segmentation registers must be correspondingly updated.
For instance, when the CPL is equal to 3 (User Mode), the ds register must contain the Segment Selector of the user data segment,but when the CPL is equal to 0, the ds register must contain the Segment Selector of the kernel data segment.
A similar situation occurs for the ss register. It must refer to a User Mode stack inside the user data segment when the CPL is 3, and it must refer to a Kernel Mode stack inside the kernel data segment when the CPL is 0. When switching from User Mode to Kernel Mode, Linux always makes sure that the ss register contains the Segment Selector of the kernel data segment.
Based on the above, I have few questions:
1) What are the RPL in the segment selectors stored in the other segmentation registers used for?
2) When a system call is executing on behalf of a user process, the RPL in cs will be set to 3 (Difference between DPL and RPL in x86). In this case will the data segment (ds) contain __USER_DS instead of __KERNEL_DS, and if so how can the implementation of the system call have access to kernel data structures etc?