Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Crash Utility (http://www.linux-archive.org/crash-utility/)
-   -   ptov command (http://www.linux-archive.org/crash-utility/680353-ptov-command.html)

"Karlsson, Jan" 07-05-2012 11:01 AM

ptov command
 
Hi Dave
*
I have a question about the ptov command. Ptov only handles kernel virtual addresses and their corresponding physical addresses. However if you give ptov a physical address that does not correspond to a kernel virtual address it still answers with an address. Users might get confused and do not know when to trust ptov, especially as the inverse command vtop always works.
*
So I would like to restrict ptov to give a result only when it is valid. The idea I have is that if ptov returns a valid virtual address then vtop on that address should give the same physical address back again. True??
*
cmd_ptov() in memory.c
* ....
* vaddr = PTOV(paddr);
* kvtop(0, vaddr, &paddr_tst, 0);
* if (paddr != paddr_tst) ... invalid vaddr, do not print it ...
*
Any comments?
*
Jan
*
Jan Karlsson
Senior Software Engineer
MIB
*
Sony Mobile Communications
Tel: +46703062174
sonymobile.com
*

*
--
Crash-utility mailing list
Crash-utility@redhat.com
https://www.redhat.com/mailman/listinfo/crash-utility

Dave Anderson 07-05-2012 01:47 PM

ptov command
 
----- Original Message -----
>
> Hi Dave
>
> I have a question about the ptov command. Ptov only handles kernel
> virtual addresses and their corresponding physical addresses.
> However if you give ptov a physical address that does not correspond
> to a kernel virtual address it still answers with an address. Users
> might get confused and do not know when to trust ptov, especially as
> the inverse command vtop always works.
>
> So I would like to restrict ptov to give a result only when it is
> valid. The idea I have is that if ptov returns a valid virtual
> address then vtop on that address should give the same physical
> address back again. True??
>
> cmd_ptov() in memory.c
>
> ....
>
> vaddr = PTOV(paddr);
> kvtop(0, vaddr, &paddr_tst, 0);
> if (paddr != paddr_tst) ... invalid vaddr, do not print it ...
>
> Any comments?
>
> Jan

Sounds reasonable, at least for the 32-bit arches. I don't think it's
necessary for any 64-bit arch. And you'd also need to account for kvtop()
failing outright (and returning FALSE).

Dave

--
Crash-utility mailing list
Crash-utility@redhat.com
https://www.redhat.com/mailman/listinfo/crash-utility

"Karlsson, Jan" 07-06-2012 06:43 AM

ptov command
 
Below you find my version of the ptov function. I have just added a few lines and placed them under "#if defined(ARM)". The test is reasonable for ARM so I would appreciate if you include it. For other platforms please do whatever you like.

Jan


void
cmd_ptov(void)
{
int c;
ulong vaddr;
physaddr_t paddr;
#if defined(ARM)
physaddr_t paddr_tst;
#endif
char buf1[BUFSIZE];
char buf2[BUFSIZE];
int others;

while ((c = getopt(argcnt, args, "")) != EOF) {
switch(c)
{
default:
argerrs++;
break;
}
}

if (argerrs || !args[optind])
cmd_usage(pc->curcmd, SYNOPSIS);

others = 0;
while (args[optind]) {
paddr = htoll(args[optind], FAULT_ON_ERROR, NULL);
vaddr = PTOV(paddr);

#if defined(ARM)
if (kvtop(0, vaddr, &paddr_tst, 0) && paddr_tst==paddr) {
#endif
fprintf(fp, "%s%s %s
", others++ ? "
" : "",
mkstring(buf1, VADDR_PRLEN, LJUST, "VIRTUAL"),
mkstring(buf2, VADDR_PRLEN, LJUST, "PHYSICAL"));
fprintf(fp, "%s %s
",
mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(vaddr)),
mkstring(buf2, VADDR_PRLEN, LJUST|LONGLONG_HEX,
MKSTR(&paddr)));
#if defined(ARM)
} else {
fprintf(fp, "Unknown virtual address for physical address 0x%08llx
", paddr);
}
#endif

optind++;
}
}


Jan Karlsson
Senior Software Engineer
MIB
*
Sony Mobile Communications
Tel: +46703062174
sonymobile.com
*


-----Original Message-----
From: crash-utility-bounces@redhat.com [mailto:crash-utility-bounces@redhat.com] On Behalf Of Dave Anderson
Sent: torsdag den 5 juli 2012 15:48
To: Discussion list for crash utility usage, maintenance and development
Subject: Re: [Crash-utility] ptov command



----- Original Message -----
>
> Hi Dave
>
> I have a question about the ptov command. Ptov only handles kernel
> virtual addresses and their corresponding physical addresses.
> However if you give ptov a physical address that does not correspond
> to a kernel virtual address it still answers with an address. Users
> might get confused and do not know when to trust ptov, especially as
> the inverse command vtop always works.
>
> So I would like to restrict ptov to give a result only when it is
> valid. The idea I have is that if ptov returns a valid virtual
> address then vtop on that address should give the same physical
> address back again. True??
>
> cmd_ptov() in memory.c
>
> ....
>
> vaddr = PTOV(paddr);
> kvtop(0, vaddr, &paddr_tst, 0);
> if (paddr != paddr_tst) ... invalid vaddr, do not print it ...
>
> Any comments?
>
> Jan

Sounds reasonable, at least for the 32-bit arches. I don't think it's
necessary for any 64-bit arch. And you'd also need to account for kvtop()
failing outright (and returning FALSE).

Dave

--
Crash-utility mailing list
Crash-utility@redhat.com
https://www.redhat.com/mailman/listinfo/crash-utility

--
Crash-utility mailing list
Crash-utility@redhat.com
https://www.redhat.com/mailman/listinfo/crash-utility

Dave Anderson 07-06-2012 03:39 PM

ptov command
 
----- Original Message -----
> Below you find my version of the ptov function. I have just added a
> few lines and placed them under "#if defined(ARM)". The test is
> reasonable for ARM so I would appreciate if you include it. For
> other platforms please do whatever you like.
>
> Jan
>
>
> void
> cmd_ptov(void)
> {
> int c;
> ulong vaddr;
> physaddr_t paddr;
> #if defined(ARM)
> physaddr_t paddr_tst;
> #endif
> char buf1[BUFSIZE];
> char buf2[BUFSIZE];
> int others;
>
> while ((c = getopt(argcnt, args, "")) != EOF) {
> switch(c)
> {
> default:
> argerrs++;
> break;
> }
> }
>
> if (argerrs || !args[optind])
> cmd_usage(pc->curcmd, SYNOPSIS);
>
> others = 0;
> while (args[optind]) {
> paddr = htoll(args[optind], FAULT_ON_ERROR, NULL);
> vaddr = PTOV(paddr);
>
> #if defined(ARM)
> if (kvtop(0, vaddr, &paddr_tst, 0) && paddr_tst==paddr) {
> #endif
> fprintf(fp, "%s%s %s
", others++ ? "
" : "",
> mkstring(buf1, VADDR_PRLEN, LJUST, "VIRTUAL"),
> mkstring(buf2, VADDR_PRLEN, LJUST, "PHYSICAL"));
> fprintf(fp, "%s %s
",
> mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(vaddr)),
> mkstring(buf2, VADDR_PRLEN, LJUST|LONGLONG_HEX,
> MKSTR(&paddr)));
> #if defined(ARM)
> } else {
> fprintf(fp, "Unknown virtual address for physical address
> 0x%08llx
", paddr);
> }
> #endif
>
> optind++;
> }
> }

I hate the "#ifdef ARM" sections and the error message doesn't fit
into multiple-argument usage. How's this work for you?

--- crash-6.0.8/memory.c.orig 2012-07-06 11:28:13.000000000 -0400
+++ crash-6.0.8/memory.c 2012-07-06 11:32:02.000000000 -0400
@@ -2975,9 +2975,9 @@
void
cmd_ptov(void)
{
- int c;
+ int c, unknown;
ulong vaddr;
- physaddr_t paddr;
+ physaddr_t paddr, paddr_test;
char buf1[BUFSIZE];
char buf2[BUFSIZE];
int others;
@@ -2999,10 +2999,14 @@
paddr = htoll(args[optind], FAULT_ON_ERROR, NULL);
vaddr = PTOV(paddr);

+ unknown = BITS32() && (!kvtop(0, vaddr, &paddr_test, 0) ||
+ (paddr_test != paddr));
+
fprintf(fp, "%s%s %s
", others++ ? "
" : "",
mkstring(buf1, VADDR_PRLEN, LJUST, "VIRTUAL"),
mkstring(buf2, VADDR_PRLEN, LJUST, "PHYSICAL"));
- fprintf(fp, "%s %s
",
+ fprintf(fp, "%s %s
", unknown ?
+ mkstring(buf1, VADDR_PRLEN, LJUST, "unknown") :
mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(vaddr)),
mkstring(buf2, VADDR_PRLEN, LJUST|LONGLONG_HEX,


With one my sample ARM dumps, it looks like this:

crash> kmem -p
PAGE PHYSICAL MAPPING INDEX CNT FLAGS
c0b47000 80000000 0 0 0 0
c0b47020 80001000 0 0 0 0
c0b47040 80002000 0 0 0 0
... [ cut ] ...
c0d46fa0 8fffd000 0 0 1 400
c0d46fc0 8fffe000 0 0 1 400
c0d46fe0 8ffff000 0 0 1 400
crash>

crash> ptov 7ffff000 80000000 8ffff000 9000000
VIRTUAL PHYSICAL
unknown 7ffff000

VIRTUAL PHYSICAL
c0000000 80000000

VIRTUAL PHYSICAL
cffff000 8ffff000

VIRTUAL PHYSICAL
unknown 9000000
crash>

Dave


--
Crash-utility mailing list
Crash-utility@redhat.com
https://www.redhat.com/mailman/listinfo/crash-utility

"Karlsson, Jan" 07-09-2012 07:33 AM

ptov command
 
Hi Dave

I have tested your solution and it works fine and solves the problem I have seen. It is also in several ways better than my solution, so please include it in the next release.

Thanks
Jan

Jan Karlsson
Senior Software Engineer
MIB
*
Sony Mobile Communications
Tel: +46703062174
sonymobile.com
*


-----Original Message-----
From: crash-utility-bounces@redhat.com [mailto:crash-utility-bounces@redhat.com] On Behalf Of Dave Anderson
Sent: fredag den 6 juli 2012 17:40
To: Discussion list for crash utility usage, maintenance and development
Subject: Re: [Crash-utility] ptov command



----- Original Message -----
> Below you find my version of the ptov function. I have just added a
> few lines and placed them under "#if defined(ARM)". The test is
> reasonable for ARM so I would appreciate if you include it. For other
> platforms please do whatever you like.
>
> Jan
>
>
> void
> cmd_ptov(void)
> {
> int c;
> ulong vaddr;
> physaddr_t paddr;
> #if defined(ARM)
> physaddr_t paddr_tst;
> #endif
> char buf1[BUFSIZE];
> char buf2[BUFSIZE];
> int others;
>
> while ((c = getopt(argcnt, args, "")) != EOF) {
> switch(c)
> {
> default:
> argerrs++;
> break;
> }
> }
>
> if (argerrs || !args[optind])
> cmd_usage(pc->curcmd, SYNOPSIS);
>
> others = 0;
> while (args[optind]) {
> paddr = htoll(args[optind], FAULT_ON_ERROR, NULL);
> vaddr = PTOV(paddr);
>
> #if defined(ARM)
> if (kvtop(0, vaddr, &paddr_tst, 0) && paddr_tst==paddr) { #endif
> fprintf(fp, "%s%s %s
", others++ ? "
" : "",
> mkstring(buf1, VADDR_PRLEN, LJUST, "VIRTUAL"),
> mkstring(buf2, VADDR_PRLEN, LJUST, "PHYSICAL"));
> fprintf(fp, "%s %s
",
> mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(vaddr)),
> mkstring(buf2, VADDR_PRLEN, LJUST|LONGLONG_HEX,
> MKSTR(&paddr)));
> #if defined(ARM)
> } else {
> fprintf(fp, "Unknown virtual address for physical address
> 0x%08llx
", paddr);
> }
> #endif
>
> optind++;
> }
> }

I hate the "#ifdef ARM" sections and the error message doesn't fit into multiple-argument usage. How's this work for you?

--- crash-6.0.8/memory.c.orig 2012-07-06 11:28:13.000000000 -0400
+++ crash-6.0.8/memory.c 2012-07-06 11:32:02.000000000 -0400
@@ -2975,9 +2975,9 @@
void
cmd_ptov(void)
{
- int c;
+ int c, unknown;
ulong vaddr;
- physaddr_t paddr;
+ physaddr_t paddr, paddr_test;
char buf1[BUFSIZE];
char buf2[BUFSIZE];
int others;
@@ -2999,10 +2999,14 @@
paddr = htoll(args[optind], FAULT_ON_ERROR, NULL);
vaddr = PTOV(paddr);

+ unknown = BITS32() && (!kvtop(0, vaddr, &paddr_test, 0) ||
+ (paddr_test != paddr));
+
fprintf(fp, "%s%s %s
", others++ ? "
" : "",
mkstring(buf1, VADDR_PRLEN, LJUST, "VIRTUAL"),
mkstring(buf2, VADDR_PRLEN, LJUST, "PHYSICAL"));
- fprintf(fp, "%s %s
",
+ fprintf(fp, "%s %s
", unknown ?
+ mkstring(buf1, VADDR_PRLEN, LJUST, "unknown") :
mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(vaddr)),
mkstring(buf2, VADDR_PRLEN, LJUST|LONGLONG_HEX,


With one my sample ARM dumps, it looks like this:

crash> kmem -p
PAGE PHYSICAL MAPPING INDEX CNT FLAGS
c0b47000 80000000 0 0 0 0
c0b47020 80001000 0 0 0 0
c0b47040 80002000 0 0 0 0
... [ cut ] ...
c0d46fa0 8fffd000 0 0 1 400
c0d46fc0 8fffe000 0 0 1 400
c0d46fe0 8ffff000 0 0 1 400
crash>

crash> ptov 7ffff000 80000000 8ffff000 9000000
VIRTUAL PHYSICAL
unknown 7ffff000

VIRTUAL PHYSICAL
c0000000 80000000

VIRTUAL PHYSICAL
cffff000 8ffff000

VIRTUAL PHYSICAL
unknown 9000000
crash>

Dave



--
Crash-utility mailing list
Crash-utility@redhat.com
https://www.redhat.com/mailman/listinfo/crash-utility


All times are GMT. The time now is 11:59 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.