# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID ed696467fe642fe3e8d2722048dd97267b9b3727
# Parent 52cec91b75606d6000e09e3c72854adf051ee99b
[PTRACE] Fix ptrace for hvm guests.
Signed-off-by: Nitin A Kamble <nitin.a.kamble@xxxxxxxxx>
---
tools/libxc/xc_ptrace.c | 77 +++++++++++++++++++++++--------------------
tools/libxc/xc_ptrace.h | 3 -
tools/libxc/xc_ptrace_core.c | 7 ++-
tools/libxc/xg_private.h | 10 +++++
4 files changed, 56 insertions(+), 41 deletions(-)
diff -r 52cec91b7560 -r ed696467fe64 tools/libxc/xc_ptrace.c
--- a/tools/libxc/xc_ptrace.c Wed May 24 12:01:25 2006 +0100
+++ b/tools/libxc/xc_ptrace.c Wed May 24 14:12:40 2006 +0100
@@ -185,7 +185,7 @@ map_domain_va_32(
void *guest_va,
int perm)
{
- unsigned long l1p, p, va = (unsigned long)guest_va;
+ unsigned long l2e, l1e, l1p, p, va = (unsigned long)guest_va;
uint32_t *l2, *l1;
static void *v[MAX_VIRT_CPUS];
@@ -194,18 +194,20 @@ map_domain_va_32(
if ( l2 == NULL )
return NULL;
- l1p = to_ma(cpu, l2[l2_table_offset(va)]);
+ l2e = l2[l2_table_offset_i386(va)];
munmap(l2, PAGE_SIZE);
- if ( !(l1p & _PAGE_PRESENT) )
- return NULL;
+ if ( !(l2e & _PAGE_PRESENT) )
+ return NULL;
+ l1p = to_ma(cpu, l2e);
l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ,
l1p >> PAGE_SHIFT);
if ( l1 == NULL )
return NULL;
- p = to_ma(cpu, l1[l1_table_offset(va)]);
+ l1e = l1[l1_table_offset_i386(va)];
munmap(l1, PAGE_SIZE);
- if ( !(p & _PAGE_PRESENT) )
- return NULL;
+ if ( !(l1e & _PAGE_PRESENT) )
+ return NULL;
+ p = to_ma(cpu, l1e);
if ( v[cpu] != NULL )
munmap(v[cpu], PAGE_SIZE);
v[cpu] = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p
>> PAGE_SHIFT);
@@ -223,7 +225,7 @@ map_domain_va_pae(
void *guest_va,
int perm)
{
- unsigned long l2p, l1p, p, va = (unsigned long)guest_va;
+ unsigned long l3e, l2e, l1e, l2p, l1p, p, va = (unsigned long)guest_va;
uint64_t *l3, *l2, *l1;
static void *v[MAX_VIRT_CPUS];
@@ -232,26 +234,29 @@ map_domain_va_pae(
if ( l3 == NULL )
return NULL;
- l2p = to_ma(cpu, l3[l3_table_offset_pae(va)]);
+ l3e = l3[l3_table_offset_pae(va)];
munmap(l3, PAGE_SIZE);
- if ( !(l2p & _PAGE_PRESENT) )
- return NULL;
+ if ( !(l3e & _PAGE_PRESENT) )
+ return NULL;
+ l2p = to_ma(cpu, l3e);
l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ,
l2p >> PAGE_SHIFT);
if ( l2 == NULL )
return NULL;
- l1p = to_ma(cpu, l2[l2_table_offset_pae(va)]);
+ l2e = l2[l2_table_offset_pae(va)];
munmap(l2, PAGE_SIZE);
- if ( !(l1p & _PAGE_PRESENT) )
- return NULL;
+ if ( !(l2e & _PAGE_PRESENT) )
+ return NULL;
+ l1p = to_ma(cpu, l2e);
l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p
>> PAGE_SHIFT);
if ( l1 == NULL )
return NULL;
- p = to_ma(cpu, l1[l1_table_offset_pae(va)]);
+ l1e = l1[l1_table_offset_pae(va)];
munmap(l1, PAGE_SIZE);
- if ( !(p & _PAGE_PRESENT) )
- return NULL;
+ if ( !(l1e & _PAGE_PRESENT) )
+ return NULL;
+ p = to_ma(cpu, l1e);
if ( v[cpu] != NULL )
munmap(v[cpu], PAGE_SIZE);
v[cpu] = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p
>> PAGE_SHIFT);
@@ -269,9 +274,10 @@ map_domain_va_64(
void *guest_va,
int perm)
{
- unsigned long l3p, l2p, l1p, l1e, p, va = (unsigned long)guest_va;
+ unsigned long l4e, l3e, l2e, l1e, l3p, l2p, l1p, p, va = (unsigned
long)guest_va;
uint64_t *l4, *l3, *l2, *l1;
static void *v[MAX_VIRT_CPUS];
+
if ((ctxt[cpu].ctrlreg[4] & 0x20) == 0 ) /* legacy ia32 mode */
return map_domain_va_32(xc_handle, cpu, guest_va, perm);
@@ -281,40 +287,41 @@ map_domain_va_64(
if ( l4 == NULL )
return NULL;
- l3p = to_ma(cpu, l4[l4_table_offset(va)]);
+ l4e = l4[l4_table_offset(va)];
munmap(l4, PAGE_SIZE);
- if ( !(l3p & _PAGE_PRESENT) )
- return NULL;
+ if ( !(l4e & _PAGE_PRESENT) )
+ return NULL;
+ l3p = to_ma(cpu, l4e);
l3 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ,
l3p >> PAGE_SHIFT);
if ( l3 == NULL )
return NULL;
- l2p = to_ma(cpu, l3[l3_table_offset(va)]);
+ l3e = l3[l3_table_offset(va)];
munmap(l3, PAGE_SIZE);
- if ( !(l2p & _PAGE_PRESENT) )
- return NULL;
+ if ( !(l3e & _PAGE_PRESENT) )
+ return NULL;
+ l2p = to_ma(cpu, l3e);
l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ,
l2p >> PAGE_SHIFT);
if ( l2 == NULL )
return NULL;
l1 = NULL;
- l1e = to_ma(cpu, l2[l2_table_offset(va)]);
- if ( !(l1e & _PAGE_PRESENT) )
- {
- munmap(l2, PAGE_SIZE);
- return NULL;
- }
- l1p = l1e >> PAGE_SHIFT;
- if (l1e & 0x80) { /* 2M pages */
+ l2e = l2[l2_table_offset(va)];
+ munmap(l2, PAGE_SIZE);
+ if ( !(l2e & _PAGE_PRESENT) )
+ return NULL;
+ l1p = to_ma(cpu, l2e);
+ if (l2e & 0x80) { /* 2M pages */
p = to_ma(cpu, (l1p + l1_table_offset(va)) << PAGE_SHIFT);
} else { /* 4K pages */
- l1p = to_ma(cpu, l1p);
l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm,
l1p >> PAGE_SHIFT);
- munmap(l2, PAGE_SIZE);
if ( l1 == NULL )
return NULL;
- p = to_ma(cpu, l1[l1_table_offset(va)]);
+ l1e = l1[l1_table_offset(va)];
+ if ( !(l1e & _PAGE_PRESENT) )
+ return NULL;
+ p = to_ma(cpu, l1e);
}
if ( v[cpu] != NULL )
munmap(v[cpu], PAGE_SIZE);
diff -r 52cec91b7560 -r ed696467fe64 tools/libxc/xc_ptrace.h
--- a/tools/libxc/xc_ptrace.h Wed May 24 12:01:25 2006 +0100
+++ b/tools/libxc/xc_ptrace.h Wed May 24 14:12:40 2006 +0100
@@ -7,7 +7,6 @@
#define X86_CR0_PE 0x00000001 /* Enable Protected Mode (RW) */
#define X86_CR0_PG 0x80000000 /* Paging (RW) */
#define BSD_PAGE_MASK (PAGE_SIZE-1)
-#define PDRSHIFT 22
#define PSL_T 0x00000100 /* trace enable bit */
#ifdef __x86_64__
@@ -162,8 +161,6 @@ struct gdb_regs {
#endif
#define printval(x) printf("%s = %lx\n", #x, (long)x);
-#define vtopdi(va) ((va) >> PDRSHIFT)
-#define vtopti(va) (((va) >> PAGE_SHIFT) & 0x3ff)
#endif
typedef void (*thr_ev_handler_t)(long);
diff -r 52cec91b7560 -r ed696467fe64 tools/libxc/xc_ptrace_core.c
--- a/tools/libxc/xc_ptrace_core.c Wed May 24 12:01:25 2006 +0100
+++ b/tools/libxc/xc_ptrace_core.c Wed May 24 14:12:40 2006 +0100
@@ -3,6 +3,7 @@
#include <sys/ptrace.h>
#include <sys/wait.h>
#include "xc_private.h"
+#include "xg_private.h"
#include "xc_ptrace.h"
#include <time.h>
@@ -54,7 +55,7 @@ map_domain_va_core(unsigned long domfd,
}
cr3_virt[cpu] = v;
}
- if ((pde = cr3_virt[cpu][vtopdi(va)]) == 0) /* logical address */
+ if ((pde = cr3_virt[cpu][l2_table_offset_i386(va)]) == 0) /* logical
address */
return NULL;
if (ctxt[cpu].flags & VGCF_HVM_GUEST)
pde = p2m_array[pde >> PAGE_SHIFT] << PAGE_SHIFT;
@@ -70,7 +71,7 @@ map_domain_va_core(unsigned long domfd,
return NULL;
pde_virt[cpu] = v;
}
- if ((page = pde_virt[cpu][vtopti(va)]) == 0) /* logical address */
+ if ((page = pde_virt[cpu][l1_table_offset_i386(va)]) == 0) /* logical
address */
return NULL;
if (ctxt[cpu].flags & VGCF_HVM_GUEST)
page = p2m_array[page >> PAGE_SHIFT] << PAGE_SHIFT;
@@ -84,7 +85,7 @@ map_domain_va_core(unsigned long domfd,
map_mtop_offset(page_phys[cpu]));
if (v == MAP_FAILED)
{
- printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page,
vtopti(va));
+ printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page,
l1_table_offset_i386(va));
page_phys[cpu] = 0;
return NULL;
}
diff -r 52cec91b7560 -r ed696467fe64 tools/libxc/xg_private.h
--- a/tools/libxc/xg_private.h Wed May 24 12:01:25 2006 +0100
+++ b/tools/libxc/xg_private.h Wed May 24 14:12:40 2006 +0100
@@ -48,6 +48,8 @@ unsigned long csum_page (void * page);
#define L2_PAGETABLE_SHIFT_PAE 21
#define L3_PAGETABLE_SHIFT_PAE 30
+#define L2_PAGETABLE_SHIFT_I386 22
+
#if defined(__i386__)
#define L1_PAGETABLE_SHIFT 12
#define L2_PAGETABLE_SHIFT 22
@@ -61,6 +63,9 @@ unsigned long csum_page (void * page);
#define L1_PAGETABLE_ENTRIES_PAE 512
#define L2_PAGETABLE_ENTRIES_PAE 512
#define L3_PAGETABLE_ENTRIES_PAE 4
+
+#define L1_PAGETABLE_ENTRIES_I386 1024
+#define L2_PAGETABLE_ENTRIES_I386 1024
#if defined(__i386__)
#define L1_PAGETABLE_ENTRIES 1024
@@ -95,6 +100,11 @@ typedef unsigned long l4_pgentry_t;
#define l3_table_offset_pae(_a) \
(((_a) >> L3_PAGETABLE_SHIFT_PAE) & (L3_PAGETABLE_ENTRIES_PAE - 1))
+#define l1_table_offset_i386(_a) \
+ (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES_I386 - 1))
+#define l2_table_offset_i386(_a) \
+ (((_a) >> L2_PAGETABLE_SHIFT_I386) & (L2_PAGETABLE_ENTRIES_I386 - 1))
+
#if defined(__i386__)
#define l1_table_offset(_a) \
(((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|