Re: [PATCH] /proc/kcore: Update physical address for kcore ram and text

2017-02-23 Thread Baoquan He
CC Eric too.

On 02/13/17 at 02:25pm, Kees Cook wrote:
> On Mon, Jan 30, 2017 at 11:00 AM, Pratyush Anand  wrote:
> > CCing Andrew and Kees for their review comments.
> >
> >
> > On Wednesday 25 January 2017 10:14 AM, Pratyush Anand wrote:
> >> Currently all the p_paddr of PT_LOAD headers are assigned to 0, which is
> >> not true and could be misleading, since 0 is a valid physical address.
> >>
> >> User space tools like makedumpfile needs to know physical address for
> >> PT_LOAD segments of direct mapped regions. Therefore this patch updates
> >> paddr for such regions. It also sets an invalid paddr (-1) for other
> >> regions, so that user space tool can know whether a physical address
> >> provided in PT_LOAD is correct or not.
> >>
> >> Signed-off-by: Pratyush Anand 
> >> ---
> >> fs/proc/kcore.c | 5 -
> >> 1 file changed, 4 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
> >> index 0b80ad87b4d6..ea9f3d1ae830 100644
> >> --- a/fs/proc/kcore.c
> >> +++ b/fs/proc/kcore.c
> >> @@ -373,7 +373,10 @@ static void elf_kcore_store_hdr(char *bufp, int
> >> nphdr, int dataoff)
> >> phdr->p_flags = PF_R|PF_W|PF_X;
> >> phdr->p_offset = kc_vaddr_to_offset(m->addr) + dataoff;
> >> phdr->p_vaddr = (size_t)m->addr;
> >> - phdr->p_paddr = 0;
> >> + if (m->type == KCORE_RAM || m->type == KCORE_TEXT)
> >> + phdr->p_paddr = __pa(m->addr);
> >> + else
> >> + phdr->p_paddr = (elf_addr_t)-1;
> >> phdr->p_filesz = phdr->p_memsz = m->size;
> >> phdr->p_align = PAGE_SIZE;
> >> }
> >>
> 
> Well, CONFIG_PROC_KCORE is a generalized root KASLR exposure (though
> there are lots of such exposures). Why is the actual physical address
> needed? Can this just report the virtual address instead? Then the
> tool can build a map, but it looks like an identity map, rather than
> creating a new physical/virtual memory ASLR offset exposure?

HPE asked to add a dumped vmcore size estimate feature to makedumpfile,
just like HP UNIX does. So I added a --mem-usage option to makedumpfile
and use /proc/kcore to analyze the memory of 1st kernel. Since /proc/kcore
is a elf file which contains the mm layout of 1st kernel, it can help us
estimate how much disk space need be reserved. Later s390x people also
add support for this feature.

With kaslr enabled, page_offset becomes uncertain, and in kernel Eric
doesn't suggest exporting them into vmcoreinfo. So Pratyush tried to add
physical address of direct mapping regions. For kaslr, kcore has
exported those randomized starting address, I am not sure if it's risky
to export physical address.

It's close to our rhel dev cycle deadline, we hope this can be merged
soon. I believe we can discuss it and improve it any time if risk is
felt.

Thanks
Baoquan

___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


Re: [PATCH] /proc/kcore: Update physical address for kcore ram and text

2017-02-23 Thread Pratyush Anand

Hi Andrew/Kees,

On Tuesday 14 February 2017 07:16 AM, Pratyush Anand wrote:


Well, CONFIG_PROC_KCORE is a generalized root KASLR exposure (though
there are lots of such exposures). Why is the actual physical address
needed? Can this just report the virtual address instead? Then the
tool can build a map, but it looks like an identity map, rather than
creating a new physical/virtual memory ASLR offset exposure?


Well, having an ASLR offset information can help to translate an
identity mapped virtual address to a physical address. But that would be
an additional field in PT_LOAD header structure and an arch dependent
value.

Moreover, sending a valid physical address like 0 does not seem right.
So, IMHO it is better to fix that and send valid physical address when
available (identity mapped).

Thanks for the review.


So, whats the decision on this patch? I see that patch is lying in 
next/master. Should I expect this patch in v4.11-rc1?


Couple of user-space makedumpfile modification will depend on this 
patch. So, we can not get those makedumpfile patches merged until this 
patch hits upstream.


~Pratyush

___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


[PATCH v4] x86/mce: Don't participate in rendezvous process once nmi_shootdown_cpus() was made

2017-02-23 Thread Xunlei Pang
We met an issue for kdump: after kdump kernel boots up,
and there comes a broadcasted mce in first kernel, the
other cpus remaining in first kernel will enter the old
mce handler of first kernel, then timeout and panic due
to MCE synchronization, finally reset the kdump cpus.

This patch lets cpus stay quiet after nmi_shootdown_cpus(),
so after kdump boots, cpus remaining in 1st kernel should
not do anything except clearing MCG_STATUS. This is useful
for kdump to let vmcore dumping perform as hard as it can.

Previous efforts:
https://patchwork.kernel.org/patch/6167631/
https://lists.gt.net/linux/kernel/2146557

Cc: Naoya Horiguchi 
Suggested-by: Borislav Petkov 
Signed-off-by: Xunlei Pang 
---
v1->v2:
- Using crashing_cpu according to Borislav's suggestion.

v2->v3:
- Used crashing_cpu in mce.c explicitly, not skip crashing_cpu.
- Added some comments.

v3->v4:
- Added more code comments according to Tony's feedback.

 arch/x86/include/asm/reboot.h|  1 +
 arch/x86/kernel/cpu/mcheck/mce.c | 17 +++--
 arch/x86/kernel/reboot.c |  5 +++--
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
index 2cb1cc2..fc62ba8 100644
--- a/arch/x86/include/asm/reboot.h
+++ b/arch/x86/include/asm/reboot.h
@@ -15,6 +15,7 @@ struct machine_ops {
 };
 
 extern struct machine_ops machine_ops;
+extern int crashing_cpu;
 
 void native_machine_crash_shutdown(struct pt_regs *regs);
 void native_machine_shutdown(void);
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 8e9725c..b65505f 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -49,6 +49,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "mce-internal.h"
 
@@ -1127,9 +1128,21 @@ void do_machine_check(struct pt_regs *regs, long 
error_code)
 * on Intel.
 */
int lmce = 1;
+   int cpu = smp_processor_id();
 
-   /* If this CPU is offline, just bail out. */
-   if (cpu_is_offline(smp_processor_id())) {
+   /*
+* Cases to bail out to avoid rendezvous process timeout:
+* 1)If this CPU is offline.
+* 2)If crashing_cpu was set, e.g. entering kdump,
+*   we need to skip cpus remaining in 1st kernel.
+*   Note: there is a small window between kexecing
+*   and kdump kernel establishing new mce handler,
+*   if some MCE comes within the window, there is
+*   no valid mce handler due to pgtable changing,
+*   let's just face the fate.
+*/
+   if (cpu_is_offline(cpu) ||
+   (crashing_cpu != -1 && crashing_cpu != cpu)) {
u64 mcgstatus;
 
mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index e244c19..92ecf4b 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -749,10 +749,11 @@ void machine_crash_shutdown(struct pt_regs *regs)
 #endif
 
 
+/* This keeps a track of which one is crashing cpu. */
+int crashing_cpu = -1;
+
 #if defined(CONFIG_SMP)
 
-/* This keeps a track of which one is crashing cpu. */
-static int crashing_cpu;
 static nmi_shootdown_cb shootdown_callback;
 
 static atomic_t waiting_for_crash_ipi;
-- 
1.8.3.1


___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


Re: [PATCH v2] gitignore: add two generated files in purgatory

2017-02-23 Thread Pratyush Anand



On Tuesday 21 February 2017 09:48 PM, Eric DeVolder wrote:

This patch adds the two generated files below to .gitignore,
so that 'git status' does not complain about them.

purgatory/purgatory.map
purgatory/purgatory.ro.sym

Signed-off-by: Eric DeVolder 


I think, it will be good to have these two files in .gitignore.

Reviewed-by: Pratyush Anand 

Infact, there should be few more which is generated by developer like 
tags etc..


/tags
cscope.*
*.patch


---
v2: Incorporated feedback
- A bit more specific why these files added to .gitignore
v1: Posted to kexec-tools mailing list
---
 .gitignore | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.gitignore b/.gitignore
index 81e03ab..1ab52d9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,5 @@
 /configure
 /include/config.h.in
 /include/config.h
+/purgatory/purgatory.map
+/purgatory/purgatory.ro.sym




~Pratyush

___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec