How does the Linux knows it's maximal physical address range, especially when it builds the paging tables hierarchy? How does it know not to map a virtual address to physical address that is beyond the maximum available hardware RAM? Is there are some CPU instruction for this, or it gets the info elsewhere?
See the related OSDev wiki page:
There are BIOS functions to get the information, for example this one (Quote from OSDev):
By far the best way to detect the memory of a PC is by using the INT 0x15, EAX = 0xE820 command. This function is available on all PCs built since 2002, and on most existing PCs before then. It is the only BIOS function that can detect memory areas above 4G. It is meant to be the ultimate memory detection BIOS function.
Another source of information is the E820 wikipedia page (note the E820 in the quote above!). To my knowledge, detect_memory_e820(), which is located in arch/x86/boot/memory.c for x86 architecture, retrieves the physical memmap from the BIOS.
Also see http://www.uruk.org/orig-grub/mem64mb.html for a detailed description of physical address map-related interrupts.