Re: [PATCH] KVM: PPC: Book3S HV: Tracepoints for KVM HV guest interactions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 19.11.14 22:54, Suresh E. Warrier wrote:
> 
> 
> On 11/14/2014 04:56 AM, Alexander Graf wrote:
>>
>>
>>
>>> Am 14.11.2014 um 00:29 schrieb Suresh E. Warrier <warrier@xxxxxxxxxxxxxxxxxx>:
>>>
>>> This patch adds trace points in the guest entry and exit code and also
>>> for exceptions handled by the host in kernel mode - hypercalls and page
>>> faults. The new events are added to /sys/kernel/debug/tracing/events
>>> under a new subsystem called kvm_hv.
>>>
>>> Acked-by: Paul Mackerras <paulus@xxxxxxxxx>
>>> Signed-off-by: Suresh Warrier <warrier@xxxxxxxxxxxxxxxxxx>
>>> ---
>>> arch/powerpc/kvm/book3s_64_mmu_hv.c |  12 +-
>>> arch/powerpc/kvm/book3s_hv.c        |  19 ++
>>> arch/powerpc/kvm/trace_hv.h         | 497 ++++++++++++++++++++++++++++++++++++
>>> 3 files changed, 525 insertions(+), 3 deletions(-)
>>> create mode 100644 arch/powerpc/kvm/trace_hv.h
>>>
>>> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
>>> index 70feb7b..20cbad1 100644
>>> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
>>> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
>>> @@ -38,6 +38,7 @@
>>> #include <asm/cputable.h>
>>>
>>> #include "book3s_hv_cma.h"
>>> +#include "trace_hv.h"
>>>
>>> /* POWER7 has 10-bit LPIDs, PPC970 has 6-bit LPIDs */
>>> #define MAX_LPID_970    63
>>> @@ -627,6 +628,8 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
>>>    gfn = gpa >> PAGE_SHIFT;
>>>    memslot = gfn_to_memslot(kvm, gfn);
>>>
>>> +    trace_kvm_page_fault_enter(vcpu, hpte, memslot, ea, dsisr);
>>> +
>>>    /* No memslot means it's an emulated MMIO region */
>>>    if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID))
>>>        return kvmppc_hv_emulate_mmio(run, vcpu, gpa, ea,
>>> @@ -639,6 +642,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
>>>    mmu_seq = kvm->mmu_notifier_seq;
>>>    smp_rmb();
>>>
>>> +    ret = -EFAULT;
>>>    is_io = 0;
>>>    pfn = 0;
>>>    page = NULL;
>>> @@ -662,7 +666,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
>>>        }
>>>        up_read(&current->mm->mmap_sem);
>>>        if (!pfn)
>>> -            return -EFAULT;
>>> +            goto out_put;
>>>    } else {
>>>        page = pages[0];
>>>        if (PageHuge(page)) {
>>> @@ -690,14 +694,14 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
>>>        pfn = page_to_pfn(page);
>>>    }
>>>
>>> -    ret = -EFAULT;
>>>    if (psize > pte_size)
>>>        goto out_put;
>>>
>>>    /* Check WIMG vs. the actual page we're accessing */
>>>    if (!hpte_cache_flags_ok(r, is_io)) {
>>>        if (is_io)
>>> -            return -EFAULT;
>>> +            goto out_put;
>>> +
>>>        /*
>>>         * Allow guest to map emulated device memory as
>>>         * uncacheable, but actually make it cacheable.
>>> @@ -753,6 +757,8 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
>>>        SetPageDirty(page);
>>>
>>>  out_put:
>>> +    trace_kvm_page_fault_exit(vcpu, hpte, ret);
>>> +
>>>    if (page) {
>>>        /*
>>>         * We drop pages[0] here, not page because page might
>>> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
>>> index 69d4085..5143d17 100644
>>> --- a/arch/powerpc/kvm/book3s_hv.c
>>> +++ b/arch/powerpc/kvm/book3s_hv.c
>>> @@ -57,6 +57,9 @@
>>>
>>> #include "book3s.h"
>>>
>>> +#define CREATE_TRACE_POINTS
>>> +#include "trace_hv.h"
>>> +
>>> /* #define EXIT_DEBUG */
>>> /* #define EXIT_DEBUG_SIMPLE */
>>> /* #define EXIT_DEBUG_INT */
>>> @@ -1679,6 +1682,7 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc)
>>>    list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) {
>>>        kvmppc_start_thread(vcpu);
>>>        kvmppc_create_dtl_entry(vcpu, vc);
>>> +        trace_kvm_guest_enter(vcpu);
>>>    }
>>>
>>>    /* Set this explicitly in case thread 0 doesn't have a vcpu */
>>> @@ -1687,6 +1691,9 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc)
>>>
>>>    vc->vcore_state = VCORE_RUNNING;
>>>    preempt_disable();
>>> +
>>> +    trace_kvmppc_run_core(vc, 0);
>>> +
>>>    spin_unlock(&vc->lock);
>>>
>>>    kvm_guest_enter();
>>> @@ -1732,6 +1739,8 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc)
>>>            kvmppc_core_pending_dec(vcpu))
>>>            kvmppc_core_dequeue_dec(vcpu);
>>>
>>> +        trace_kvm_guest_exit(vcpu);
>>> +
>>>        ret = RESUME_GUEST;
>>>        if (vcpu->arch.trap)
>>>            ret = kvmppc_handle_exit_hv(vcpu->arch.kvm_run, vcpu,
>>> @@ -1757,6 +1766,8 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc)
>>>            wake_up(&vcpu->arch.cpu_run);
>>>        }
>>>    }
>>> +
>>> +    trace_kvmppc_run_core(vc, 1);
>>> }
>>>
>>> /*
>>> @@ -1783,11 +1794,13 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc)
>>>
>>>    prepare_to_wait(&vc->wq, &wait, TASK_INTERRUPTIBLE);
>>>    vc->vcore_state = VCORE_SLEEPING;
>>> +    trace_kvmppc_vcore_blocked(vc, 0);
>>>    spin_unlock(&vc->lock);
>>>    schedule();
>>>    finish_wait(&vc->wq, &wait);
>>>    spin_lock(&vc->lock);
>>>    vc->vcore_state = VCORE_INACTIVE;
>>> +    trace_kvmppc_vcore_blocked(vc, 1);
>>> }
>>>
>>> static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
>>> @@ -1796,6 +1809,8 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
>>>    struct kvmppc_vcore *vc;
>>>    struct kvm_vcpu *v, *vn;
>>>
>>> +    trace_kvmppc_run_vcpu_enter(vcpu);
>>> +
>>>    kvm_run->exit_reason = 0;
>>>    vcpu->arch.ret = RESUME_GUEST;
>>>    vcpu->arch.trap = 0;
>>> @@ -1825,6 +1840,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
>>>            VCORE_EXIT_COUNT(vc) == 0) {
>>>            kvmppc_create_dtl_entry(vcpu, vc);
>>>            kvmppc_start_thread(vcpu);
>>> +            trace_kvm_guest_enter(vcpu);
>>>        } else if (vc->vcore_state == VCORE_SLEEPING) {
>>>            wake_up(&vc->wq);
>>>        }
>>> @@ -1889,6 +1905,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
>>>        wake_up(&v->arch.cpu_run);
>>>    }
>>>
>>> +    trace_kvmppc_run_vcpu_exit(vcpu, kvm_run);
>>>    spin_unlock(&vc->lock);
>>>    return vcpu->arch.ret;
>>> }
>>> @@ -1934,7 +1951,9 @@ static int kvmppc_vcpu_run_hv(struct kvm_run *run, struct kvm_vcpu *vcpu)
>>>
>>>        if (run->exit_reason == KVM_EXIT_PAPR_HCALL &&
>>>            !(vcpu->arch.shregs.msr & MSR_PR)) {
>>> +            trace_kvm_hcall_enter(vcpu);
>>>            r = kvmppc_pseries_do_hcall(vcpu);
>>> +            trace_kvm_hcall_exit(vcpu, r);
>>>            kvmppc_core_prepare_to_enter(vcpu);
>>>        } else if (r == RESUME_PAGE_FAULT) {
>>>            srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
>>> diff --git a/arch/powerpc/kvm/trace_hv.h b/arch/powerpc/kvm/trace_hv.h
>>> new file mode 100644
>>> index 0000000..2d2e55f
>>> --- /dev/null
>>> +++ b/arch/powerpc/kvm/trace_hv.h
>>> @@ -0,0 +1,497 @@
>>> +#if !defined(_TRACE_KVM_HV_H) || defined(TRACE_HEADER_MULTI_READ)
>>> +#define _TRACE_KVM_HV_H
>>> +
>>> +#include <linux/tracepoint.h>
>>> +
>>> +#undef TRACE_SYSTEM
>>> +#define TRACE_SYSTEM kvm_hv
>>> +#define TRACE_INCLUDE_PATH .
>>> +#define TRACE_INCLUDE_FILE trace_hv
>>> +
>>> +#define kvm_trace_symbol_exit \
>>> +    {0x100, "SYSTEM_RESET"}, \
>>> +    {0x200, "MACHINE_CHECK"}, \
>>> +    {0x300, "DATA_STORAGE"}, \
>>> +    {0x380, "DATA_SEGMENT"}, \
>>> +    {0x400, "INST_STORAGE"}, \
>>> +    {0x480, "INST_SEGMENT"}, \
>>> +    {0x500, "EXTERNAL"}, \
>>> +    {0x502, "EXTERNAL_HV"}, \
>>> +    {0x600, "ALIGNMENT"}, \
>>> +    {0x700, "PROGRAM"}, \
>>> +    {0x800, "FP_UNAVAIL"}, \
>>> +    {0x900, "DECREMENTER"}, \
>>> +    {0x980, "HV_DECREMENTER"}, \
>>> +    {0xc00, "SYSCALL"}, \
>>> +    {0xd00, "TRACE"}, \
>>> +    {0xe00, "H_DATA_STORAGE"}, \
>>> +    {0xe20, "H_INST_STORAGE"}, \
>>> +    {0xe40, "H_EMUL_ASSIST"}, \
>>> +    {0xf00, "PERFMON"}, \
>>> +    {0xf20, "ALTIVEC"}, \
>>> +    {0xf40, "VSX"}
>>
>> Can we share these with PR?
>>
> I could move these to a new file, say trace_kvm.h and have both trace_pr.h and 
> trace_hv.h include the file. Please confirm if that works for you. Or do you 
> have a better suggestion?

Yeah, just create a trace_book3s.h file and include it from trace_pr.h
and trace_hv.h.


Alex
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux