Why are copy_from_user() and copy_to_user() needed, when the kernel is mapped into the same virtual address space as the process itself?
Having developed a few (toy) kernel modules for learning purposes, I quickly reliazed that copy_from_user() and copy_to_user() were needed to copy data from/to user-space buffers; otherwise errors related to invalid addresses resulted in crashes.
But if 0x1fffff is a virtual address pointing to a user-space buffer, then why isn't that address valid in the kernel? The kernel is in the same virtual address space, so 0x1fffff would be mapped to the same physical memory.


x86andarmthe address space mapping is the same for the kernel and process? The functions first disableSMAPbefore checking page permissions and writing/reading data? For architectures with direct mapping of physical memory, pages cannot be swapped out? – Shuzheng Oct 27 '21 at 09:52STAC/CLACin the kernel code). User pages can be swapped out even with direct mapping. – Stephen Kitt Oct 27 '21 at 10:25buster. With a direct mapping, virtual memory addresses higher than physical memory addresses would map to nothing (at least that's what I understand from the concept of a direct mapping:Xmaps toX) – Shuzheng Oct 27 '21 at 11:05physical address Xmaps tovirtual address X+page_offset_base, how can virtual addresses greater thanmaximum physical address+page_offset_baseever come into play? They are swapped out constantly? – Shuzheng Oct 27 '21 at 12:59