From: Tianyi Liu <i.pear@outlook.com> To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, Tianyi Liu <i.pear@outlook.com> Subject: [PATCH v2 1/5] KVM: Add arch specific interfaces for sampling guest callchains Date: Sun, 8 Oct 2023 22:52:20 +0800 [thread overview] Message-ID: <SY4P282MB10840154D4F09917D6528BC69DCFA@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM> (raw) In-Reply-To: <SY4P282MB1084ECBCC1B176153B9E2A009DCFA@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM> This patch adds three architecture specific interfaces and x86 implementations used by `perf kvm`: - kvm_arch_vcpu_get_frame_pointer: Return the frame pointer of vcpu, for x86 it's RBP, and for arm64 it's x29. - kvm_arch_vcpu_read_virt: Read data from a virtual address of the given guest vm. - kvm_arch_vcpu_is_64bit: Return whether the vcpu is working in 64-bit mode. It's used for determining the size of a stack frame. Since arm64 hasn't provided some foundational infrastructure, stub the arm64 implementation for now because it's a bit complex. Signed-off-by: Tianyi Liu <i.pear@outlook.com> --- arch/arm64/kvm/arm.c | 17 +++++++++++++++++ arch/x86/kvm/x86.c | 18 ++++++++++++++++++ include/linux/kvm_host.h | 4 ++++ 3 files changed, 39 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 4866b3f7b..b57b88c58 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -571,6 +571,23 @@ unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu) { return *vcpu_pc(vcpu); } + +unsigned long kvm_arch_vcpu_get_frame_pointer(struct kvm_vcpu *vcpu) +{ + /* TODO: implement */ + return NULL; +} + +bool kvm_arch_vcpu_read_virt(struct kvm_vcpu *vcpu, void *addr, void *dest, unsigned int length) +{ + /* TODO: implement */ + return false; +} + +bool kvm_arch_vcpu_is_64bit(struct kvm_vcpu *vcpu) +{ + return !vcpu_mode_is_32bit(vcpu); +} #endif static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 9f18b06bb..17dea02b7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12904,6 +12904,24 @@ unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu) return kvm_rip_read(vcpu); } +unsigned long kvm_arch_vcpu_get_frame_pointer(struct kvm_vcpu *vcpu) +{ + return kvm_register_read_raw(vcpu, VCPU_REGS_RBP); +} + +bool kvm_arch_vcpu_read_virt(struct kvm_vcpu *vcpu, void *addr, void *dest, unsigned int length) +{ + struct x86_exception e; + + /* Return true on success */ + return kvm_read_guest_virt(vcpu, addr, dest, length, &e) == X86EMUL_CONTINUE; +} + +bool kvm_arch_vcpu_is_64bit(struct kvm_vcpu *vcpu) +{ + return is_64_bit_mode(vcpu); +} + int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) { return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index fb6c6109f..f92f1a9c8 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1595,6 +1595,10 @@ static inline bool kvm_arch_intc_initialized(struct kvm *kvm) #ifdef CONFIG_GUEST_PERF_EVENTS unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu); +unsigned long kvm_arch_vcpu_get_frame_pointer(struct kvm_vcpu *vcpu); +bool kvm_arch_vcpu_read_virt(struct kvm_vcpu *vcpu, void *addr, void *dest, + unsigned int length); +bool kvm_arch_vcpu_is_64bit(struct kvm_vcpu *vcpu); void kvm_register_perf_callbacks(unsigned int (*pt_intr_handler)(void)); void kvm_unregister_perf_callbacks(void); -- 2.42.0
WARNING: multiple messages have this Message-ID (diff)
From: Tianyi Liu <i.pear@outlook.com> To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, Tianyi Liu <i.pear@outlook.com> Subject: [PATCH v2 1/5] KVM: Add arch specific interfaces for sampling guest callchains Date: Sun, 8 Oct 2023 22:52:20 +0800 [thread overview] Message-ID: <SY4P282MB10840154D4F09917D6528BC69DCFA@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM> (raw) In-Reply-To: <SY4P282MB1084ECBCC1B176153B9E2A009DCFA@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM> This patch adds three architecture specific interfaces and x86 implementations used by `perf kvm`: - kvm_arch_vcpu_get_frame_pointer: Return the frame pointer of vcpu, for x86 it's RBP, and for arm64 it's x29. - kvm_arch_vcpu_read_virt: Read data from a virtual address of the given guest vm. - kvm_arch_vcpu_is_64bit: Return whether the vcpu is working in 64-bit mode. It's used for determining the size of a stack frame. Since arm64 hasn't provided some foundational infrastructure, stub the arm64 implementation for now because it's a bit complex. Signed-off-by: Tianyi Liu <i.pear@outlook.com> --- arch/arm64/kvm/arm.c | 17 +++++++++++++++++ arch/x86/kvm/x86.c | 18 ++++++++++++++++++ include/linux/kvm_host.h | 4 ++++ 3 files changed, 39 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 4866b3f7b..b57b88c58 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -571,6 +571,23 @@ unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu) { return *vcpu_pc(vcpu); } + +unsigned long kvm_arch_vcpu_get_frame_pointer(struct kvm_vcpu *vcpu) +{ + /* TODO: implement */ + return NULL; +} + +bool kvm_arch_vcpu_read_virt(struct kvm_vcpu *vcpu, void *addr, void *dest, unsigned int length) +{ + /* TODO: implement */ + return false; +} + +bool kvm_arch_vcpu_is_64bit(struct kvm_vcpu *vcpu) +{ + return !vcpu_mode_is_32bit(vcpu); +} #endif static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 9f18b06bb..17dea02b7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12904,6 +12904,24 @@ unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu) return kvm_rip_read(vcpu); } +unsigned long kvm_arch_vcpu_get_frame_pointer(struct kvm_vcpu *vcpu) +{ + return kvm_register_read_raw(vcpu, VCPU_REGS_RBP); +} + +bool kvm_arch_vcpu_read_virt(struct kvm_vcpu *vcpu, void *addr, void *dest, unsigned int length) +{ + struct x86_exception e; + + /* Return true on success */ + return kvm_read_guest_virt(vcpu, addr, dest, length, &e) == X86EMUL_CONTINUE; +} + +bool kvm_arch_vcpu_is_64bit(struct kvm_vcpu *vcpu) +{ + return is_64_bit_mode(vcpu); +} + int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) { return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index fb6c6109f..f92f1a9c8 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1595,6 +1595,10 @@ static inline bool kvm_arch_intc_initialized(struct kvm *kvm) #ifdef CONFIG_GUEST_PERF_EVENTS unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu); +unsigned long kvm_arch_vcpu_get_frame_pointer(struct kvm_vcpu *vcpu); +bool kvm_arch_vcpu_read_virt(struct kvm_vcpu *vcpu, void *addr, void *dest, + unsigned int length); +bool kvm_arch_vcpu_is_64bit(struct kvm_vcpu *vcpu); void kvm_register_perf_callbacks(unsigned int (*pt_intr_handler)(void)); void kvm_unregister_perf_callbacks(void); -- 2.42.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-10-08 14:53 UTC|newest] Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-10-08 14:48 [PATCH v2 0/5] perf: KVM: Enable callchains for guests Tianyi Liu 2023-10-08 14:48 ` Tianyi Liu 2023-10-08 14:52 ` Tianyi Liu [this message] 2023-10-08 14:52 ` [PATCH v2 1/5] KVM: Add arch specific interfaces for sampling guest callchains Tianyi Liu 2023-10-08 21:12 ` kernel test robot 2023-10-08 21:12 ` kernel test robot 2023-10-08 21:32 ` kernel test robot 2023-10-08 21:32 ` kernel test robot 2023-10-08 22:25 ` kernel test robot 2023-10-08 22:25 ` kernel test robot 2023-10-09 3:17 ` Tianyi Liu 2023-10-09 3:17 ` Tianyi Liu 2023-10-08 14:53 ` [PATCH v2 2/5] perf kvm: Introduce guest interfaces for sampling callchains Tianyi Liu 2023-10-08 14:53 ` Tianyi Liu 2023-10-08 14:56 ` [PATCH v2 3/5] KVM: implement new perf interfaces Tianyi Liu 2023-10-08 14:56 ` Tianyi Liu 2023-10-08 14:57 ` [PATCH v2 4/5] perf kvm: Support sampling guest callchains Tianyi Liu 2023-10-08 14:57 ` Tianyi Liu 2023-10-08 19:57 ` kernel test robot 2023-10-08 19:57 ` kernel test robot 2023-10-10 16:12 ` Maxim Levitsky 2023-10-10 16:12 ` Maxim Levitsky 2023-10-11 14:44 ` Tianyi Liu 2023-10-11 14:44 ` Tianyi Liu 2023-10-12 20:41 ` kernel test robot 2023-10-12 20:41 ` kernel test robot 2023-10-08 14:57 ` [PATCH v2 5/5] perf tools: Support PERF_CONTEXT_GUEST_* flags Tianyi Liu 2023-10-08 14:57 ` Tianyi Liu 2023-10-11 16:45 ` [PATCH v2 0/5] perf: KVM: Enable callchains for guests Marc Zyngier 2023-10-11 16:45 ` Marc Zyngier 2023-10-12 6:35 ` Tianyi Liu 2023-10-12 6:35 ` Tianyi Liu 2023-10-13 14:01 ` Mark Rutland 2023-10-13 14:01 ` Mark Rutland 2023-10-20 9:21 ` Tianyi Liu 2023-10-20 9:21 ` Tianyi Liu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=SY4P282MB10840154D4F09917D6528BC69DCFA@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM \ --to=i.pear@outlook.com \ --cc=acme@kernel.org \ --cc=adrian.hunter@intel.com \ --cc=alexander.shishkin@linux.intel.com \ --cc=irogers@google.com \ --cc=jolsa@kernel.org \ --cc=kvm@vger.kernel.org \ --cc=kvmarm@lists.linux.dev \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-perf-users@vger.kernel.org \ --cc=mark.rutland@arm.com \ --cc=mingo@redhat.com \ --cc=namhyung@kernel.org \ --cc=pbonzini@redhat.com \ --cc=peterz@infradead.org \ --cc=seanjc@google.com \ --cc=x86@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.