Hi,

From: Mike Larkin <[email protected]>
Subject: Re: amd64: update PTDpaddr with new PA of PML4 for libkvm
Date: Wed, 13 Feb 2019 01:01:28 -0800

> On Wed, Feb 13, 2019 at 05:40:45PM +0900, Naoki Fukaumi wrote:
>> Hi Mike Larkin,
>> 
>> since pmap_kernel is randomized, savecore(libkvm) cannot save core
>> dump from dump device. (savecore: magic number mismatch)
>> 
>> updating PTDpaddr fixes this issue.
>> 
>> by the way, is there any problem to use proc0.p_addr->u_pcb.pcb_cr3
>> instead of PTDpaddr in cpu_dump()?
>> 
> 
> Thanks for noticing this!
> 
> Does using the proc0.p_addr->u_pcb.pcb_cr3 expansion also work?
> If so, we may be able to remove PTPpaddr entirely, if we remove the
> other usage in cpu_dump also.

here is "remove PTDpaddr" patch.

it works, but now I'm not sure which is better... using extra
"PTDpaddr" might be simpler... at least, I don't need to worry about
"is this chain really fine?" ;)

----

for "using PTDpaddr" case, I think it might be better to

- set PTDpaddr later in locore0.S (around setting pcb_cr3)
- use a term "PML4" than "PTD"/"PDP" in comments

to make thing more clear (for me).

Regards,

--
FUKAUMI Naoki

Index: sys/arch/amd64/amd64/locore.S
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/locore.S,v
retrieving revision 1.113
diff -u -p -u -p -r1.113 locore.S
--- sys/arch/amd64/amd64/locore.S       24 Jan 2019 00:00:50 -0000      1.113
+++ sys/arch/amd64/amd64/locore.S       15 Feb 2019 07:07:09 -0000
@@ -172,7 +172,7 @@ _C_LABEL(lapic_isr):
        .globl  _C_LABEL(ssym),_C_LABEL(esym),_C_LABEL(boothowto)
        .globl  _C_LABEL(bootdev)
        .globl  _C_LABEL(bootinfo), _C_LABEL(bootinfo_size), _C_LABEL(atdevbase)
-       .globl  _C_LABEL(proc0paddr),_C_LABEL(PTDpaddr)
+       .globl  _C_LABEL(proc0paddr)
        .globl  _C_LABEL(biosbasemem)
        .globl  _C_LABEL(bootapiver)
        .globl  _C_LABEL(pg_nx)
@@ -198,7 +198,6 @@ _C_LABEL(atdevbase):        .quad   0       # location 
 _C_LABEL(bootapiver):  .long   0       # /boot API version
 _C_LABEL(bootdev):     .long   0       # device we booted from
 _C_LABEL(proc0paddr):  .quad   0
-_C_LABEL(PTDpaddr):    .quad   0       # paddr of PTD, for libkvm
 #ifndef REALBASEMEM
 _C_LABEL(biosbasemem): .long   0       # base memory reported by BIOS
 #else
Index: sys/arch/amd64/amd64/locore0.S
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/locore0.S,v
retrieving revision 1.16
diff -u -p -u -p -r1.16 locore0.S
--- sys/arch/amd64/amd64/locore0.S      24 Jan 2019 00:57:14 -0000      1.16
+++ sys/arch/amd64/amd64/locore0.S      15 Feb 2019 07:07:09 -0000
@@ -548,11 +548,6 @@ store_pte:
        movl    %ebp, 4(%ebx)
        popl    %ebp
 
-       /* Save phys. addr of PTD, for libkvm. */
-       movl    $RELOC(PTDpaddr),%ebp
-       movl    %esi,(%ebp)
-       movl    $0,4(%ebp)
-
        /*
         * Startup checklist:
         * 1. Enable PAE (and SSE while here).
Index: sys/arch/amd64/amd64/machdep.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/machdep.c,v
retrieving revision 1.254
diff -u -p -u -p -r1.254 machdep.c
--- sys/arch/amd64/amd64/machdep.c      21 Jan 2019 06:18:37 -0000      1.254
+++ sys/arch/amd64/amd64/machdep.c      15 Feb 2019 07:07:09 -0000
@@ -925,7 +925,7 @@ cpu_dump(void)
        /*
         * Add the machine-dependent header info.
         */
-       cpuhdrp->ptdpaddr = PTDpaddr;
+       cpuhdrp->ptdpaddr = proc0.p_addr->u_pcb.pcb_cr3;
        cpuhdrp->nmemsegs = mem_cluster_cnt;
 
        /*
Index: sys/arch/amd64/include/pmap.h
===================================================================
RCS file: /cvs/src/sys/arch/amd64/include/pmap.h,v
retrieving revision 1.73
diff -u -p -u -p -r1.73 pmap.h
--- sys/arch/amd64/include/pmap.h       21 Jan 2019 06:18:37 -0000      1.73
+++ sys/arch/amd64/include/pmap.h       15 Feb 2019 07:07:09 -0000
@@ -344,9 +344,6 @@ struct pv_entry {                   /* locked by its lis
  * global kernel variables
  */
 
-/* PTDpaddr: is the physical address of the kernel's PDP */
-extern u_long PTDpaddr;
-
 extern struct pmap kernel_pmap_store;  /* kernel pmap */
 
 extern long nkptp[];

Reply via email to