Skip to contentSkip to conversation

xen/arm: Implement hypercall for dirty page tracing

PATCH Jaeyong Yoo 4 participants 6 messages Oct 8, 2013 – Oct 16, 2013

lore
Share & tools
lore
#0 lore raw
Quoted 48 lines

------- Original Message -------
Sender : Julien Grall<[email protected]>
Date : 2013-10-07 22:02 (GMT+09:00)
Title : Re: [Xen-devel] [PATCH v4 8/9] xen/arm: Implement hypercall for dirty page tracing

Quoted 14 lines · Jaeyong Yoo

Add hypercall (shadow op: enable/disable and clean/peek dirted page bitmap). It consists of two parts: dirty page detecting and saving.
For detecting, we setup the guest p2m's leaf PTE read-only and whenever the guest tries to write something, permission fault happens and traps into xen. The permission-faulted GPA should be saved for the toolstack (when it wants to see which pages are dirted). For this purpose, we temporarily save the GPAs into linked list by using 'add_mapped_vaddr' function and when toolstack wants (log_dirty_op function) the GPAs are copied into bitmap and the linnked list is flushed.

Additionally, for supporting parallel migration of domUs, vlpt area should be context switched.

Signed-off-by Jaeyong Yoo

---

[..]

Quoted 14 lines
xen/arch/arm/traps.c +2 -0
index 4c0fc32..3b78ed2 100644
@@ -1313,6 +1313,8 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs,
     const char *msg;
     int rc, level = -1;
     mmio_info_t info;
+    int page_fault = ((dabt.dfsc & FSC_MASK) ==
+                      (FSC_FLT_PERM + FSC_3D_LEVEL) && dabt.write);
 
     if ( !check_conditional_instr(regs, hsr) )
     {

xen/arch/arm/traps.c static void do_trap_data_abort_guest(struct cpu_user_regs *regs, · line 1332

Quoted 5 lines
xen/arch/arm/traps.c +1 -1
@@ -1327,22 +1329,23 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs,
     info.gva = READ_SYSREG64(FAR_EL2);
 #endif
 
-    if (dabt.s1ptw)
+    if ( dabt.s1ptw && !page_fault )

I think checking !page_fault is nearly everywhere is error-prone when this function will be modified.

Can you do something like this?

Quoted 8 lines

if ( page_fault )
// Your code to handle page fault
else
{
// handle_mmio
}

It will avoid && !page_fault.

That looks better.

Quoted 26 lines
Quoted 26 lines
xen/arch/arm/traps.c +4 -3
         goto bad_data_abort;
 
     rc = gva_to_ipa(info.gva, &info.gpa);
-    if ( rc == -EFAULT )
+    if ( rc == -EFAULT && !page_fault )
         goto bad_data_abort;
 
     /* XXX: Decode the instruction if ISS is not valid */
-    if ( !dabt.valid )
+    if ( !dabt.valid && !page_fault )
         goto bad_data_abort;
 
     /*
      * Erratum 766422: Thumb store translation fault to Hypervisor may
      * not have correct HSR Rt value.
      */
-    if ( cpu_has_erratum_766422() && (regs->cpsr & PSR_THUMB) && dabt.write )
+    if ( cpu_has_erratum_766422() && (regs->cpsr & PSR_THUMB) && dabt.write
+            && !page_fault)
     {
         rc = decode_instruction(regs, &info.dabt);
         if ( rc )
@@ -1358,6 +1361,16 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs,
         return;
     }
 
Quoted 9 lines

xen/arch/arm/traps.c static void do_trap_data_abort_guest(struct cpu_user_regs *regs, · line 1370

Quoted 7 lines
xen/arch/arm/traps.c +7 -0
+    /* handle permission fault on write */
+    if ( page_fault )
+    {
+        if ( current->domain->arch.dirty.mode == 0 )
+           goto bad_data_abort;
+
+        handle_page_fault(current->domain, info.gpa);

You must call advance_pc(regs, hsr) here.

I got it.

Quoted 8 lines
Quoted 5 lines
xen/arch/arm/traps.c +3 -0
+        return;
+    }
+
 bad_data_abort:
Signature · 1 line
Julien Grall
#1 lore raw
Quoted 11 lines · Jaeyong Yoo
Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+    /* handle permission fault on write */
+    if ( page_fault )
+    {
+        if ( current->domain->arch.dirty.mode == 0 )
+           goto bad_data_abort;
+
+        handle_page_fault(current->domain, info.gpa);

You must call advance_pc(regs, hsr) here.

I got it.

Are you sure about this? Eugene's reasoning that we need to replay the faulting instruction seemed pretty sound.

Ian.

#2 lore raw
Quoted 19 lines

-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Ian Campbell
Sent: Tuesday, October 08, 2013 5:46 PM
To: [email protected]
Cc: Julien Grall; [email protected]
Subject: Re: [Xen-devel] [PATCH v4 8/9] xen/arm: Implement hypercall for dirty page tracing

Quoted 8 lines · Jaeyong Yoo
Quoted 8 lines
Quoted 7 lines
(quoted diff) +7 -0
+    /* handle permission fault on write */
+    if ( page_fault )
+    {
+        if ( current->domain->arch.dirty.mode == 0 )
+           goto bad_data_abort;
+
+        handle_page_fault(current->domain, info.gpa);
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

You must call advance_pc(regs, hsr) here.

I got it.

Are you sure about this? Eugene's reasoning that we need to replay the faulting instruction seemed pretty sound.

Oh, I've got confused. I think Eugene's reasoning is correct. handle_mmio is for emulating and handle_page_fault is the generic fault, which should be resolved and repeat the instruction.
Sorry for the confusion.

Jaeyong

Quoted 8 lines

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw

If we move necessary checking into handle_page_fault routine, so the resulting patch for traps.c will look more simple:

xen/arch/arm/traps.c +9 -0
@@ -1313,6 +1313,8 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs,
     const char *msg;
     int rc, level = -1;
     mmio_info_t info;
+    int page_fault = ( (dabt.dfsc & FSC_MASK) ==
+                          (FSC_FLT_PERM | FSC_3D_LEVEL) && dabt.write );
 
     if ( !check_conditional_instr(regs, hsr) )
     {
@@ -1334,6 +1336,13 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs,
     if ( rc == -EFAULT )
         goto bad_data_abort;
 
+    /* domU page fault handling for guest live migration */
+    /* dabt.valid can be 0 here */
+    if ( page_fault && handle_page_fault(current->domain, info.gpa) )
+    {
+        /* Do not modify pc after page fault to repeat memory operation */
+        return;
+    }
     /* XXX: Decode the instruction if ISS is not valid */
     if ( !dabt.valid )
         goto bad_data_abort;

Will it be acceptable, or you think "else" statement looks more better?

Where handle_page_fault returns zero if dirty page tracing is not enabled for domain (dirty.mode==0) or address is not valid for domain (having memory map we check it), so MMIO and faults from dom0 are not handled by handle_page_fault.

The handle_page_fault routine (see [PATCH v4 7/9] xen/arm: Implement virtual-linear page table for guest p2m mapping in live migration) will be:

int handle_page_fault(struct domain *d, paddr_t addr)
{

    lpae_t *vlp2m_pte = 0;
    vaddr_t start, end;

    if (!d->arch.dirty.mode) return 0;
    /* Ensure that addr is inside guest's RAM */
    get_gma_start_end(d, &start, &end);
    if ( addr < start || addr > end ) return 0;

    vlp2m_pte = get_vlpt_3lvl_pte(addr);
    if ( vlp2m_pte->p2m.valid && vlp2m_pte->p2m.write == 0 )
    {
        lpae_t pte = *vlp2m_pte;
        pte.p2m.write = 1;
        write_pte(vlp2m_pte, pte);
        flush_tlb_local();

        /* in order to remove mappings in cleanup stage */
        add_mapped_vaddr(d, addr);
    }

    return 1;
}

Best,
Evgeny.

#4 lore raw
Quoted 31 lines · Eugene Fedotov

If we move necessary checking into handle_page_fault routine, so the resulting patch for traps.c will look more simple:

xen/arch/arm/traps.c +2 -0
@@ -1313,6 +1313,8 @@ static void do_trap_data_abort_guest(struct
 cpu_user_regs *regs,
     const char *msg;
     int rc, level = -1;
     mmio_info_t info;
+    int page_fault = ( (dabt.dfsc & FSC_MASK) ==
+                          (FSC_FLT_PERM | FSC_3D_LEVEL) && dabt.write );
 
     if ( !check_conditional_instr(regs, hsr) )
     {
xen/arch/arm/traps.c +7 -0
@@ -1334,6 +1336,13 @@ static void do_trap_data_abort_guest(struct
 cpu_user_regs *regs,
     if ( rc == -EFAULT )
         goto bad_data_abort;
 
+    /* domU page fault handling for guest live migration */
+    /* dabt.valid can be 0 here */
+    if ( page_fault && handle_page_fault(current->domain, info.gpa) )
+    {
+        /* Do not modify pc after page fault to repeat memory operation */
+        return;
+    }
     /* XXX: Decode the instruction if ISS is not valid */
     if ( !dabt.valid )
         goto bad_data_abort;
Quoted 1 line

Will it be acceptable, or you think "else" statement looks more better?

I'm fine with this solution.

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw
Quoted 32 lines · Julien Grall
Quoted 31 lines · Eugene Fedotov

If we move necessary checking into handle_page_fault routine, so the resulting patch for traps.c will look more simple:

xen/arch/arm/traps.c +2 -0
@@ -1313,6 +1313,8 @@ static void do_trap_data_abort_guest(struct
 cpu_user_regs *regs,
     const char *msg;
     int rc, level = -1;
     mmio_info_t info;
+    int page_fault = ( (dabt.dfsc & FSC_MASK) ==
+                          (FSC_FLT_PERM | FSC_3D_LEVEL) && dabt.write );
 
     if ( !check_conditional_instr(regs, hsr) )
     {
xen/arch/arm/traps.c +7 -0
@@ -1334,6 +1336,13 @@ static void do_trap_data_abort_guest(struct
 cpu_user_regs *regs,
     if ( rc == -EFAULT )
         goto bad_data_abort;
 
+    /* domU page fault handling for guest live migration */
+    /* dabt.valid can be 0 here */
+    if ( page_fault && handle_page_fault(current->domain, info.gpa) )
+    {
+        /* Do not modify pc after page fault to repeat memory operation */
+        return;
+    }
     /* XXX: Decode the instruction if ISS is not valid */
     if ( !dabt.valid )
         goto bad_data_abort;
Quoted 3 lines
Quoted 1 line

Will it be acceptable, or you think "else" statement looks more better?

I'm fine with this solution.

Looks good to me too, assuming you are happy with the ordering of MMIO handling vs page faults.

Quoted 3 lines

Cheers,