kexec: add phys_offset field
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): 427318169.1232291272467931013.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com
Quoted 90 lines · ----- "Mika Westerberg
Quoted 71 lines · ext Dave Anderson
Quoted 68 lines · ----- "Mika Westerberg
Quoted 27 lines · ext Dave Anderson
Quoted 6 lines · ----- "Mika Westerberg
Idea here was to make sure that virtual addresses in
PT_LOADsegments are calculated correctly based onPHYS_OFFSETfield. For example with OMAP3, physical memory starts at0x80000000so for0xc0000000(PAGE_OFFSET) we get:Quoted 7 lines
phdr->p_vaddr = 0x80000000 + 0xc0000000 = 0x40000000which is not correct. But taking
PHYS_OFFSETinto equation we getphdr->p_vaddr = 0x80000000 + 0xc0000000 - 0x80000000 = 0xc0000000which is correct.
Yes, I understand completely -- we've been there... ;-)
The issue is that there would be a disconnect between the actual kernel virtual addresses used in the vmlinux file vs. your "calculated" virtual addresses in the header, and to me that goes against the grain of what the
p_vaddrfield is supposed to mean.The ELF spec defines them:
p_vaddrThis member gives the virtual address at which the first
byte of the segment resides in memory.Quoted 8 lines
p_paddrOn systems for which physical addressing is relevant, this
member is reserved for the segment's physical address. Because System V ignores physical addressing for application programs, this member has unspecified contents for executable files and shared objects.To me, the term "virtual address" means the virtual addresses used by the executable. Your scheme "calculates" a
p_vaddrbased upon thep_paddr.Sorry, I have to ask some clarifications to understand this.
If the kernel image is linked at virtual address
0xc0008000which is the case with ARM kernel for example. Then how following is legitimate kernel virtual address?phdr->p_vaddr = mstart + elf_info->page_offset;if the first physical memory region starts for example at
0x80000000, andPAGE_OFFSETis0xc0000000we get:phdr->p_vaddr = 0x80000000 + 0xc0000000this results virtual address
0x40000000(in 32-bit) for the kernel direct mapped region, which I think is not the same as used by the executable (the vmlinux file):% objdump -h vmlinux
vmlinux: file format elf32-little
Sections:
Idx Name Size VMA LMA File off Algn
0 .note.gnu.build-id 00000024 00000000 00000000 00008000 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .init0001f6edc0008000c000800000010000 2**5
CONTENTS, ALLOC, LOAD, CODE
2 .text0031706ac0028000c002800000030000 2**6
CONTENTS, ALLOC, LOAD, READONLY, CODE
...Quoted 7 lines
Quoted 1 line
Am I missing something?
I may be missing something w/respect to 32-bit x86, but AIUI, the unity-mapped region can only map the first 1GB of physical memory, starting at physical address 0. So you couldn't do what you suggest, i.e., where the resultant unity-mapped address wraps around into the user-space region.
Yeah, but this is what happens with the current code :(
Quoted 5 lines
But for x86, their is no concept of a mapped kernel region in addition to the unity-mapped region(s), as there is with
x86_64and ia64. It's presumed that the primary kernel is based at physical adress 0, so when thePAGE_OFFSETis stripped off, you have the physical address.With ARM we have (for the kernel direct mapped region):
Quoted 7 lines
paddr = vaddr -
PAGE_OFFSET+PHYS_OFFSETso it is related to
PHYS_OFFSET.Is there any (other) way of doing this so that we could get
p_vaddrcorrect? I checked makedumpfile but it seems not to handlep_vaddrat all so it probably won't help if we run the dump through it.
When you say "we" do you mean ARM only?
All I'm saying is that things "just work" for the currently-supported architectures. The most recent sample x86 kdump vmcore I have looks like this:
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align NOTE 0x0000b4 0x00000000 0x00000000 0x00450 0x00450 0 LOAD 0x000504 0xc0000000 0x00000000 0xa0000 0xa0000 RWE 0 LOAD 0x0a0504 0xc0100000 0x00100000 0xf00000 0xf00000 RWE 0 LOAD 0xfa0504 0xc5000000 0x05000000 0x1afc0000 0x1afc0000 RWE 0
Regardless whether the virtual address is in the static kernel text and data section (which is mapped in a special region on x86_64 and ia64) or just generic physical memory above that, it's all zero-based, where the virtual-to-physical translation simply requires stripping of the PAGE_OFFSET. The p_vaddr values above match the kernel virtual addresses used by the corresponding x86 vmlinux.
So all I'm asking is that you don't muck with that! ;-)
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 10 lines · ext Dave Anderson
Quoted 9 lines · ----- "Mika Westerberg
Quoted 4 lines
But for x86, their is no concept of a mapped kernel region in addition to the unity-mapped region(s), as there is with
x86_64and ia64. It's presumed that the primary kernel is based at physical adress 0, so when thePAGE_OFFSETis stripped off, you have the physical address.With ARM we have (for the kernel direct mapped region):
paddr = vaddr -
PAGE_OFFSET+PHYS_OFFSET
Quoted 7 lines
Quoted 5 lines
so it is related to
PHYS_OFFSET.Is there any (other) way of doing this so that we could get
p_vaddrcorrect? I checked makedumpfile but it seems not to handlep_vaddrat all so it probably won't help if we run the dump through it.When you say "we" do you mean ARM only?
Yes :)
Quoted 10 lines
All I'm saying is that things "just work" for the currently-supported architectures. The most recent sample x86 kdump vmcore I have looks like this:
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align NOTE 0x0000b4 0x00000000 0x00000000 0x00450 0x00450 0 LOAD 0x000504 0xc0000000 0x00000000 0xa0000 0xa0000 RWE 0 LOAD 0x0a0504 0xc0100000 0x00100000 0xf00000 0xf00000 RWE 0 LOAD 0xfa0504 0xc5000000 0x05000000 0x1afc0000 0x1afc0000 RWE 0
Quoted 8 lines
Regardless whether the virtual address is in the static kernel text and data section (which is mapped in a special region on
x86_64and ia64) or just generic physical memory above that, it's all zero-based, where the virtual-to-physical translation simply requires stripping of thePAGE_OFFSET. Thep_vaddrvalues above match the kernel virtual addresses used by the corresponding x86 vmlinux.So all I'm asking is that you don't muck with that! ;-)
I'll promise that I don't break it.
So how about following? This allows ARM (and maybe some future archs as well) to redefine phys_to_virt() but default implementation should work with others.
Thanks,
MW
From dcfda0e78ae9bfe3c9ff5d186c660e5ce1892fbb Mon Sep 17 00:00:00 2001
From: Mika Westerberg <[email protected]>
Date: Thu, 29 Apr 2010 11:07:14 +0300
Subject: [PATCH] kexec: introduce phys_to_virt() function
This function is used by ELF crashdump code which prepares crash memory headers for the dump capture kernel. Most architecture can use default version which just adds PAGE_OFFSET to the virtual address but some architectures might need some special handling.
--- kexec/Makefile | 2 ++ kexec/crashdump-elf.c | 2 +- kexec/crashdump.h | 3 +++ kexec/phys_to_virt.c | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 1 deletions(-) create mode 100644 kexec/phys_to_virt.c
kexec/Makefile +2 -0
@@ -39,6 +39,8 @@ $(ARCH)_PROC_IOMEM = kexec/proc_iomem.c KEXEC_SRCS += $($(ARCH)_PROC_IOMEM) $(ARCH)_VIRT_TO_PHYS = kexec/virt_to_phys.c KEXEC_SRCS += $($(ARCH)_VIRT_TO_PHYS) +$(ARCH)_PHYS_TO_VIRT = kexec/phys_to_virt.c +KEXEC_SRCS += $($(ARCH)_PHYS_TO_VIRT) $(ARCH)_ADD_SEGMENT = kexec/add_segment.c KEXEC_SRCS += $($(ARCH)_ADD_SEGMENT) $(ARCH)_ADD_BUFFER = kexec/add_buffer.c
kexec/crashdump-elf.c +1 -1
@@ -236,7 +236,7 @@ int FUNC(struct kexec_info *info,* memory region. */ phdr->p_paddr = mstart; - phdr->p_vaddr = mstart + elf_info->page_offset; + phdr->p_vaddr =phys_to_virt (elf_info, mstart); phdr->p_filesz = phdr->p_memsz = mend - mstart +1 ;/* Do we need any alignment of segments? */ phdr->p_align =0 ;
kexec/crashdump.h +3 -0
@@ -46,6 +46,9 @@ int crash_create_elf64_headers(struct kexec_info *info,unsigned long crash_architecture (struct crash_elf_info *elf_info); +unsigned long phys_to_virt (struct crash_elf_info *elf_info, +unsigned long paddr); +int xen_present (void );unsigned long xen_architecture (struct crash_elf_info *elf_info);int xen_get_nr_phys_cpus (void );
kexec/phys_to_virt.c new file +16 -0
@@ -0,0 +1,16 @@ +#include "kexec.h" +#include "crashdump.h" + +/** +* virt_to_phys() - translate physical address to virtual address +* @paddr: physical address to translate +* +* For most architectures physical address is simply virtual address minus +* PAGE_OFFSET. Architectures that don't follow this convention should provide +* their own implementation. +*/ +unsigned long +phys_to_virt (struct crash_elf_info *elf_info,unsigned long paddr) +{ +return paddr + elf_info->page_offset; +}
Signature · 7 lines
1.5.6.5 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec