vmcore: call remap_pfn_range() separately for respective partial pages
Subsystems (4)
PATCH 1/1 vmcore: call remap_pfn_range() separately for respective partial pages
Hello Vivek,
Here is a patch set for mmap failure for /proc/vmcore. Could you try to use this on the problematic system?
This patch doesn't copy partial pages to the 2nd kernel, only prepares vmcore objects for respective partial pages to invoke remap_pfn_range() for individual partial pages.
Quoted 1 line
From
c83dddd23be2a2972dcb3f252598c39abfa23078Mon Sep 17 00:00:00 2001
From: HATAYAMA Daisuke <[email protected]>
Date: Thu, 28 Nov 2013 14:51:22 +0900
Subject: [PATCH] vmcore: call remap_pfn_range() separately for respective
partial pages
Acording to the report by Vivek in
https://lkml.org/lkml/2013/11/13/439, on some specific systems, some of the System RAM ranges don't end at page boundary and the later part of the same page is used for some kind of ACPI data. As a result, remap_pfn_range() to the partial page failed if mapping range covers a boundary of the System RAM part and the ACPI data part in the partial page, due to the detection of different cache types in track_pfn_remap().
To resolve the issue, call remap_pfn_range() separately for respective partial pages, not for multiple consequtive pages that don't either start or end at page boundary, by creating vmcore objects for respective partial pages.
This patch never changes shape of /proc/vmcore visible from user-land.
--- fs/proc/vmcore.c | 108 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 84 insertions(+), 24 deletions(-)
fs/proc/vmcore.c +84 -24
@@ -816,26 +816,56 @@ static int __init process_ptload_program_headers_elf64(char *elfptr, vmcore_off = elfsz + elfnotes_sz;for (i =0 ; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) { -u64 paddr, start, end, size; +u64 start, end, size, rest; +u64 start_up, start_down, end_up, end_down;if (phdr_ptr->p_type !=PT_LOAD )continue ; - paddr = phdr_ptr->p_offset; - start =rounddown (paddr,PAGE_SIZE ); - end =roundup (paddr + phdr_ptr->p_memsz,PAGE_SIZE ); - size = end - start; + start = phdr_ptr->p_offset; + start_up =roundup (start,PAGE_SIZE ); + start_down =rounddown (start,PAGE_SIZE ); + end = phdr_ptr->p_offset + phdr_ptr->p_memsz; + end_up =roundup (end,PAGE_SIZE ); + end_down =rounddown (end,PAGE_SIZE ); + size = end_up - start_down; + rest = phdr_ptr->p_memsz; + +if (!PAGE_ALIGNED (start)) { + new =get_new_element (); +if (!new) +return -ENOMEM ; + new->paddr = start_down; + new->size =PAGE_SIZE ; +list_add_tail (&new->list, vc_list); + rest -=min (start_up, end) - start; + }/* Add this contiguous chunk of memory to vmcore list.*/ - new =get_new_element (); -if (!new) -return -ENOMEM ; - new->paddr = start; - new->size = size; -list_add_tail (&new->list, vc_list); +if (rest >0 && start_up < end_down) { + new =get_new_element (); +if (!new) +return -ENOMEM ; + new->paddr = start_up; + new->size = end_down - start_up; +list_add_tail (&new->list, vc_list); + rest -= end_down - start_up; + } + +if (rest >0 ) { + new =get_new_element (); +if (!new) +return -ENOMEM ; + new->paddr = end_down; + new->size =PAGE_SIZE ; +list_add_tail (&new->list, vc_list); + rest -= end - end_down; + } + +WARN_ON (rest >0 );/* Update the program header offset. */ - phdr_ptr->p_offset = vmcore_off + (paddr - start); + phdr_ptr->p_offset = vmcore_off + (start - start_down); vmcore_off = vmcore_off + size; }return 0 ;
@@ -859,26 +889,56 @@ static int __init process_ptload_program_headers_elf32(char *elfptr, vmcore_off = elfsz + elfnotes_sz;for (i =0 ; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) { -u64 paddr, start, end, size; +u64 start, end, size, rest; +u64 start_up, start_down, end_up, end_down;if (phdr_ptr->p_type !=PT_LOAD )continue ; - paddr = phdr_ptr->p_offset; - start =rounddown (paddr,PAGE_SIZE ); - end =roundup (paddr + phdr_ptr->p_memsz,PAGE_SIZE ); - size = end - start; + start = phdr_ptr->p_offset; + start_up =roundup (start,PAGE_SIZE ); + start_down =rounddown (start,PAGE_SIZE ); + end = phdr_ptr->p_offset + phdr_ptr->p_memsz; + end_up =roundup (end,PAGE_SIZE ); + end_down =rounddown (end,PAGE_SIZE ); + rest = phdr_ptr->p_memsz; + size = end_up - start_down; + +if (!PAGE_ALIGNED (start)) { + new =get_new_element (); +if (!new) +return -ENOMEM ; + new->paddr = start_down; + new->size =PAGE_SIZE ; +list_add_tail (&new->list, vc_list); + rest -=min (start_up, end) - start; + }/* Add this contiguous chunk of memory to vmcore list.*/ - new =get_new_element (); -if (!new) -return -ENOMEM ; - new->paddr = start; - new->size = size; -list_add_tail (&new->list, vc_list); +if (rest >0 && start_up < end_down) { + new =get_new_element (); +if (!new) +return -ENOMEM ; + new->paddr = start_up; + new->size = end_down - start_up; +list_add_tail (&new->list, vc_list); + rest -= end_down - start_up; + } + +if (rest >0 ) { + new =get_new_element (); +if (!new) +return -ENOMEM ; + new->paddr = end_down; + new->size =PAGE_SIZE ; +list_add_tail (&new->list, vc_list); + rest -= end - end_down; + } + +WARN_ON (rest >0 );/* Update the program header offset */ - phdr_ptr->p_offset = vmcore_off + (paddr - start); + phdr_ptr->p_offset = vmcore_off + (start - start_down); vmcore_off = vmcore_off + size; }return 0 ;
Signature · 5 lines
1.8.3.1 -- Thanks. HATAYAMA, Daisuke
Quoted 8 lines · HATAYAMA Daisuke
Hello Vivek,
Here is a patch set for mmap failure for
/proc/vmcore. Could you try to use this on the problematic system?This patch doesn't copy partial pages to the 2nd kernel, only prepares vmcore objects for respective partial pages to invoke
remap_pfn_range()for individual partial pages.
Hi Hatayama,
Thanks for the patch. Ok, I see that partial pages will be put in a separate call to remap_oldmem_pfn_range() and this time it should succeed.
I am wondering what do you think about your old approach of copying only relevant old memory to a new kernel page in new kernel. I kind of feel little uncomfortable with the idea of rounding down start and roudning up end to page size boundaries and then accessing the full page using oldmem interface. A safer approach might be to allocate page in new kernel, read *only* those bytes as reported by elf header and fill rest of the page with zeros.
Thanks
Vivek
Quoted 177 lines
Quoted 2 lines
From
c83dddd23be2a2972dcb3f252598c39abfa23078Mon Sep 17 00:00:00 2001From: HATAYAMA Daisuke <[email protected]>
Date: Thu, 28 Nov 2013 14:51:22 +0900
Subject: [PATCH] vmcore: callremap_pfn_range()separately for respective
partial pagesAcording to the report by Vivek in
https://lkml.org/lkml/2013/11/13/439, on some specific systems, some of the System RAM ranges don't end at page boundary and the later part of the same page is used for some kind of ACPI data. As a result,remap_pfn_range()to the partial page failed if mapping range covers a boundary of the System RAM part and the ACPI data part in the partial page, due to the detection of different cache types intrack_pfn_remap().To resolve the issue, call
remap_pfn_range()separately for respective partial pages, not for multiple consequtive pages that don't either start or end at page boundary, by creating vmcore objects for respective partial pages.This patch never changes shape of
/proc/vmcorevisible from user-land.Reported-by Vivek Goyal <[email protected]>Signed-off-by HATAYAMA Daisuke <[email protected]>--- fs/proc/vmcore.c | 108 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 84 insertions(+), 24 deletions(-)fs/proc/vmcore.c +84
-24@@ -816,26 +816,56 @@ static int __init process_ptload_program_headers_elf64(char *elfptr, vmcore_off = elfsz + elfnotes_sz;for (i =0 ; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) { -u64 paddr, start, end, size; +u64 start, end, size, rest; +u64 start_up, start_down, end_up, end_down;if (phdr_ptr->p_type !=PT_LOAD )continue ; - paddr = phdr_ptr->p_offset; - start =rounddown (paddr,PAGE_SIZE ); - end =roundup (paddr + phdr_ptr->p_memsz,PAGE_SIZE ); - size = end - start; + start = phdr_ptr->p_offset; + start_up =roundup (start,PAGE_SIZE ); + start_down =rounddown (start,PAGE_SIZE ); + end = phdr_ptr->p_offset + phdr_ptr->p_memsz; + end_up =roundup (end,PAGE_SIZE ); + end_down =rounddown (end,PAGE_SIZE ); + size = end_up - start_down; + rest = phdr_ptr->p_memsz; + +if (!PAGE_ALIGNED (start)) { + new =get_new_element (); +if (!new) +return -ENOMEM ; + new->paddr = start_down; + new->size =PAGE_SIZE ; +list_add_tail (&new->list, vc_list); + rest -=min (start_up, end) - start; + }/* Add this contiguous chunk of memory to vmcore list.*/ - new =get_new_element (); -if (!new) -return -ENOMEM ; - new->paddr = start; - new->size = size; -list_add_tail (&new->list, vc_list); +if (rest >0 && start_up < end_down) { + new =get_new_element (); +if (!new) +return -ENOMEM ; + new->paddr = start_up; + new->size = end_down - start_up; +list_add_tail (&new->list, vc_list); + rest -= end_down - start_up; + } + +if (rest >0 ) { + new =get_new_element (); +if (!new) +return -ENOMEM ; + new->paddr = end_down; + new->size =PAGE_SIZE ; +list_add_tail (&new->list, vc_list); + rest -= end - end_down; + } + +WARN_ON (rest >0 );/* Update the program header offset. */ - phdr_ptr->p_offset = vmcore_off + (paddr - start); + phdr_ptr->p_offset = vmcore_off + (start - start_down); vmcore_off = vmcore_off + size; }return 0 ;@@ -859,26 +889,56 @@ static int __init process_ptload_program_headers_elf32(char *elfptr, vmcore_off = elfsz + elfnotes_sz;for (i =0 ; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) { -u64 paddr, start, end, size; +u64 start, end, size, rest; +u64 start_up, start_down, end_up, end_down;if (phdr_ptr->p_type !=PT_LOAD )continue ; - paddr = phdr_ptr->p_offset; - start =rounddown (paddr,PAGE_SIZE ); - end =roundup (paddr + phdr_ptr->p_memsz,PAGE_SIZE ); - size = end - start; + start = phdr_ptr->p_offset; + start_up =roundup (start,PAGE_SIZE ); + start_down =rounddown (start,PAGE_SIZE ); + end = phdr_ptr->p_offset + phdr_ptr->p_memsz; + end_up =roundup (end,PAGE_SIZE ); + end_down =rounddown (end,PAGE_SIZE ); + rest = phdr_ptr->p_memsz; + size = end_up - start_down; + +if (!PAGE_ALIGNED (start)) { + new =get_new_element (); +if (!new) +return -ENOMEM ; + new->paddr = start_down; + new->size =PAGE_SIZE ; +list_add_tail (&new->list, vc_list); + rest -=min (start_up, end) - start; + }/* Add this contiguous chunk of memory to vmcore list.*/ - new =get_new_element (); -if (!new) -return -ENOMEM ; - new->paddr = start; - new->size = size; -list_add_tail (&new->list, vc_list); +if (rest >0 && start_up < end_down) { + new =get_new_element (); +if (!new) +return -ENOMEM ; + new->paddr = start_up; + new->size = end_down - start_up; +list_add_tail (&new->list, vc_list); + rest -= end_down - start_up; + } + +if (rest >0 ) { + new =get_new_element (); +if (!new) +return -ENOMEM ; + new->paddr = end_down; + new->size =PAGE_SIZE ; +list_add_tail (&new->list, vc_list); + rest -= end - end_down; + } + +WARN_ON (rest >0 );/* Update the program header offset */ - phdr_ptr->p_offset = vmcore_off + (paddr - start); + phdr_ptr->p_offset = vmcore_off + (start - start_down); vmcore_off = vmcore_off + size; }return 0 ;Signature · 5 lines
1.8.3.1 -- Thanks. HATAYAMA, Daisuke
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 23 lines · Vivek Goyal
Quoted 8 lines · HATAYAMA Daisuke
Hello Vivek,
Here is a patch set for mmap failure for
/proc/vmcore. Could you try to use this on the problematic system?This patch doesn't copy partial pages to the 2nd kernel, only prepares vmcore objects for respective partial pages to invoke
remap_pfn_range()for individual partial pages.Hi Hatayama,
Thanks for the patch. Ok, I see that partial pages will be put in a separate call to
remap_oldmem_pfn_range()and this time it should succeed.I am wondering what do you think about your old approach of copying only relevant old memory to a new kernel page in new kernel. I kind of feel little uncomfortable with the idea of rounding down start and roudning up end to page size boundaries and then accessing the full page using oldmem interface. A safer approach might be to allocate page in new kernel, read *only* those bytes as reported by elf header and fill rest of the page with zeros.
Quoted 3 lines
Thanks
Vivek
Even if copying partial pages into the 2nd kernel, we need to use ioremap() once on them, and I think the ioremap() is exactly similar to remap_pfn_range() for a single page. There seems no difference on safeness between them.
Also, current /proc/vmcore shows user-land tools a shape with holes not filled with zeros both in case of read() and in case of mmap(). If we adapt copying one without reading data in holes, shape of /proc/vmcore gets changed again.
Signature · 2 lines
Thanks. HATAYAMA, Daisuke
Quoted 24 lines · HATAYAMA Daisuke
Quoted 23 lines · Vivek Goyal
Quoted 8 lines · HATAYAMA Daisuke
Hello Vivek,
Here is a patch set for mmap failure for
/proc/vmcore. Could you try to use this on the problematic system?This patch doesn't copy partial pages to the 2nd kernel, only prepares vmcore objects for respective partial pages to invoke
remap_pfn_range()for individual partial pages.Hi Hatayama,
Thanks for the patch. Ok, I see that partial pages will be put in a separate call to
remap_oldmem_pfn_range()and this time it should succeed.I am wondering what do you think about your old approach of copying only relevant old memory to a new kernel page in new kernel. I kind of feel little uncomfortable with the idea of rounding down start and roudning up end to page size boundaries and then accessing the full page using oldmem interface. A safer approach might be to allocate page in new kernel, read *only* those bytes as reported by elf header and fill rest of the page with zeros.
Quoted 9 lines
Quoted 3 lines
Thanks
VivekEven if copying partial pages into the 2nd kernel, we need to use
ioremap()once on them, and I think theioremap()is exactly similar toremap_pfn_range()for a single page. There seems no difference on safeness between them.
I suspected some kind of pre-fetching could be performed when just page table is created. But it's common thing between the two cases above. Then, as you say, it would be safer to read less data from non-System-RAM area. Copying seems better in our case.
Another concern to reading data from partial pages is a possibility of undesirable hardware prefetch to non-System-RAM area. Is it better to disable this?
Quoted 5 lines
Also, current
/proc/vmcoreshows user-land tools a shape with holes not filled with zeros both in case ofread()and in case ofmmap(). If we adapt copying one without reading data in holes, shape of/proc/vmcoregets changed again.
So, next patch will change data in holes by filling them with zeros.
BTW, we have now page cache interface implemented by Michael Holzheu, but we have yet to use it on x86 because we've never wanted it so far. It's natural to use it to read partial pages on-demand, but I also in part think that it's not proper time to start using new mechanism that needs to be tested more. How do you think?
Signature · 2 lines
Thanks. HATAYAMA, Daisuke
On Tue, Dec 03, 2013 at 02:16:35PM +0900, HATAYAMA Daisuke wrote:
[..]
Quoted 10 lines
Quoted 5 lines
Even if copying partial pages into the 2nd kernel, we need to use
ioremap()once on them, and I think theioremap()is exactly similar toremap_pfn_range()for a single page. There seems no difference on safeness between them.I suspected some kind of pre-fetching could be performed when just page table is created. But it's common thing between the two cases above. Then, as you say, it would be safer to read less data from non-System-RAM area. Copying seems better in our case.
If we map page and just read *only* those bytes as advertized by ELF headers and fill rest of the bytes with zero, I think that seems like a right thing to do. We are only accessing what has been exported by ELF headers and not trying to read outside that range.
Quoted 3 lines
Another concern to reading data from partial pages is a possibility of undesirable hardware prefetch to non-System-RAM area. Is it better to disable this?
If it becomes an issue, may be. I think we can fix it when we run into an actual issue.
Quoted 7 lines
Quoted 6 lines
Also, current
/proc/vmcoreshows user-land tools a shape with holes not filled with zeros both in case ofread()and in case ofmmap(). If we adapt copying one without reading data in holes, shape of/proc/vmcoregets changed again.
Quoted 7 lines
So, next patch will change data in holes by filling them with zeros.
BTW, we have now page cache interface implemented by Michael Holzheu, but we have yet to use it on x86 because we've never wanted it so far. It's natural to use it to read partial pages on-demand, but I also in part think that it's not proper time to start using new mechanism that needs to be tested more. How do you think?
Do we gain anything significant by using that interface. To me it looks like this will just delay creation of mapping for partial pages. Does not save us any memory in second kernel?
I would think that in first pass, keep it simple. Copy partial pages in second kernel's memory. Read data as exported by ELF headers. Fill rest of the page with zeros. Adjust /proc/vmcore ELF headers accordingly and that should do it.
Thanks
Vivek
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 20 lines · Vivek Goyal
On Tue, Dec 03, 2013 at 02:16:35PM +0900, HATAYAMA Daisuke wrote:
[..]
Quoted 10 lines
Quoted 5 lines
Even if copying partial pages into the 2nd kernel, we need to use
ioremap()once on them, and I think theioremap()is exactly similar toremap_pfn_range()for a single page. There seems no difference on safeness between them.I suspected some kind of pre-fetching could be performed when just page table is created. But it's common thing between the two cases above. Then, as you say, it would be safer to read less data from non-System-RAM area. Copying seems better in our case.
If we map page and just read *only* those bytes as advertized by ELF headers and fill rest of the bytes with zero, I think that seems like a right thing to do. We are only accessing what has been exported by ELF headers and not trying to read outside that range.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Another concern to reading data from partial pages is a possibility of undesirable hardware prefetch to non-System-RAM area. Is it better to disable this?
If it becomes an issue, may be. I think we can fix it when we run into an actual issue.
I see.
Quoted 15 lines
Quoted 7 lines
Quoted 6 lines
Also, current
/proc/vmcoreshows user-land tools a shape with holes not filled with zeros both in case ofread()and in case ofmmap(). If we adapt copying one without reading data in holes, shape of/proc/vmcoregets changed again.Quoted 7 lines
So, next patch will change data in holes by filling them with zeros.
BTW, we have now page cache interface implemented by Michael Holzheu, but we have yet to use it on x86 because we've never wanted it so far. It's natural to use it to read partial pages on-demand, but I also in part think that it's not proper time to start using new mechanism that needs to be tested more. How do you think?
Quoted 4 lines
Do we gain anything significant by using that interface. To me it looks like this will just delay creation of mapping for partial pages. Does not save us any memory in second kernel?
Amount of partial pages seems not so problematic.
No, the number of partial pages are at most the number of System RAM entries * 2. I guess the number of the entries doesn't exceed 100 even in the worst case. Less than 1MiB even in the worst case.
The mechanism would be useful for platform that has large amount of note segment. But per-cpu note segemnt of x86 is relatively small, so meaningful platform seems the ones with a large number of cpus and they are still restrictive. Other archs that has large per-cpu note segment would already want the feature, just as Michael Holzheu explained previously for some of their s390 platform.
Quoted 5 lines
I would think that in first pass, keep it simple. Copy partial pages in second kernel's memory. Read data as exported by ELF headers. Fill rest of the page with zeros. Adjust
/proc/vmcoreELF headers accordingly and that should do it.
Yes, I also want to keep simplicity. I'll post a new patch tomorrow.
Signature · 2 lines
Thanks. HATAYAMA, Daisuke
Quoted 24 lines · HATAYAMA Daisuke
Quoted 23 lines · Vivek Goyal
Quoted 8 lines · HATAYAMA Daisuke
Hello Vivek,
Here is a patch set for mmap failure for
/proc/vmcore. Could you try to use this on the problematic system?This patch doesn't copy partial pages to the 2nd kernel, only prepares vmcore objects for respective partial pages to invoke
remap_pfn_range()for individual partial pages.Hi Hatayama,
Thanks for the patch. Ok, I see that partial pages will be put in a separate call to
remap_oldmem_pfn_range()and this time it should succeed.I am wondering what do you think about your old approach of copying only relevant old memory to a new kernel page in new kernel. I kind of feel little uncomfortable with the idea of rounding down start and roudning up end to page size boundaries and then accessing the full page using oldmem interface. A safer approach might be to allocate page in new kernel, read *only* those bytes as reported by elf header and fill rest of the page with zeros.
Quoted 8 lines
Quoted 3 lines
Thanks
VivekEven if copying partial pages into the 2nd kernel, we need to use
ioremap()once on them, and I think theioremap()is exactly similar toremap_pfn_range()for a single page. There seems no difference on safeness between them.
Hmm.., that's a good point. So anyway we will map the full page and read parts of it.
Quoted 5 lines
Also, current
/proc/vmcoreshows user-land tools a shape with holes not filled with zeros both in case ofread()and in case ofmmap(). If we adapt copying one without reading data in holes, shape of/proc/vmcoregets changed again.
I will not be worried about this as contents of those holes are undefined. And if we replace undefined with zeros, it should not break any application.
Thanks
Vivek
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec