From: Andrew Jones <ajones@ventanamicro.com>
To: zhouquan@iscas.ac.cn
Cc: anup@brainfault.org, atishp@atishpatra.org,
paul.walmsley@sifive.com, palmer@dabbelt.com,
aou@eecs.berkeley.edu, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
kvm@vger.kernel.org, kvm-riscv@lists.infradead.org,
linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 2/2] riscv: KVM: add basic support for host vs guest profiling
Date: Wed, 21 Aug 2024 14:51:09 +0200 [thread overview]
Message-ID: <20240821-5284bf727abbb08a379e1d06@orel> (raw)
In-Reply-To: <7eb3e1a8fc9f9aa0340a6a1fb88a127b767480ea.1723518282.git.zhouquan@iscas.ac.cn>
On Tue, Aug 13, 2024 at 09:24:10PM GMT, zhouquan@iscas.ac.cn wrote:
> From: Quan Zhou <zhouquan@iscas.ac.cn>
>
> For the information collected on the host side, we need to
> identify which data originates from the guest and record
> these events separately, this can be achieved by having
> KVM register perf callbacks.
>
> Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn>
> ---
> arch/riscv/include/asm/kvm_host.h | 5 +++++
> arch/riscv/kvm/Kconfig | 1 +
> arch/riscv/kvm/main.c | 12 ++++++++++--
> arch/riscv/kvm/vcpu.c | 7 +++++++
> 4 files changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h
> index 2e2254fd2a2a..d2350b08a3f4 100644
> --- a/arch/riscv/include/asm/kvm_host.h
> +++ b/arch/riscv/include/asm/kvm_host.h
> @@ -286,6 +286,11 @@ struct kvm_vcpu_arch {
> } sta;
> };
>
Let's add the same comment here that arm64 has unless you determine
that 'any event that arrives while a vCPU is loaded is considered to be
"in guest"' is not true for riscv.
> +static inline bool kvm_arch_pmi_in_guest(struct kvm_vcpu *vcpu)
> +{
> + return IS_ENABLED(CONFIG_GUEST_PERF_EVENTS) && !!vcpu;
> +}
> +
> static inline void kvm_arch_sync_events(struct kvm *kvm) {}
>
> #define KVM_RISCV_GSTAGE_TLB_MIN_ORDER 12
> diff --git a/arch/riscv/kvm/Kconfig b/arch/riscv/kvm/Kconfig
> index 26d1727f0550..0c3cbb0915ff 100644
> --- a/arch/riscv/kvm/Kconfig
> +++ b/arch/riscv/kvm/Kconfig
> @@ -32,6 +32,7 @@ config KVM
> select KVM_XFER_TO_GUEST_WORK
> select KVM_GENERIC_MMU_NOTIFIER
> select SCHED_INFO
> + select GUEST_PERF_EVENTS if PERF_EVENTS
> help
> Support hosting virtualized guest machines.
>
> diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c
> index bab2ec34cd87..734b48d8f6dd 100644
> --- a/arch/riscv/kvm/main.c
> +++ b/arch/riscv/kvm/main.c
> @@ -51,6 +51,12 @@ void kvm_arch_hardware_disable(void)
> csr_write(CSR_HIDELEG, 0);
> }
>
> +static void kvm_riscv_teardown(void)
> +{
> + kvm_riscv_aia_exit();
> + kvm_unregister_perf_callbacks();
> +}
> +
> static int __init riscv_kvm_init(void)
> {
> int rc;
> @@ -105,9 +111,11 @@ static int __init riscv_kvm_init(void)
> kvm_info("AIA available with %d guest external interrupts\n",
> kvm_riscv_aia_nr_hgei);
>
> + kvm_register_perf_callbacks(NULL);
> +
> rc = kvm_init(sizeof(struct kvm_vcpu), 0, THIS_MODULE);
> if (rc) {
> - kvm_riscv_aia_exit();
> + kvm_riscv_teardown();
> return rc;
> }
>
> @@ -117,7 +125,7 @@ module_init(riscv_kvm_init);
>
> static void __exit riscv_kvm_exit(void)
> {
> - kvm_riscv_aia_exit();
> + kvm_riscv_teardown();
>
> kvm_exit();
> }
> diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
> index 8d7d381737ee..e8ffb3456898 100644
> --- a/arch/riscv/kvm/vcpu.c
> +++ b/arch/riscv/kvm/vcpu.c
> @@ -226,6 +226,13 @@ bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)
> return (vcpu->arch.guest_context.sstatus & SR_SPP) ? true : false;
> }
>
> +#ifdef CONFIG_GUEST_PERF_EVENTS
> +unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu)
> +{
> + return vcpu->arch.guest_context.sepc;
> +}
> +#endif
> +
> vm_fault_t kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)
> {
> return VM_FAULT_SIGBUS;
> --
> 2.34.1
>
Thanks,
drew
next prev parent reply other threads:[~2024-08-21 12:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-13 13:23 [PATCH v2 0/2] riscv: Add perf support to collect KVM guest statistics from host side zhouquan
2024-08-13 13:23 ` [PATCH v2 1/2] riscv: perf: add guest vs host distinction zhouquan
2024-08-21 12:48 ` Andrew Jones
2024-08-22 6:38 ` Quan Zhou
2024-08-22 13:41 ` Andrew Jones
2024-08-13 13:24 ` [PATCH v2 2/2] riscv: KVM: add basic support for host vs guest profiling zhouquan
2024-08-21 12:51 ` Andrew Jones [this message]
2024-08-22 6:42 ` Quan Zhou
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=20240821-5284bf727abbb08a379e1d06@orel \
--to=ajones@ventanamicro.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atishp@atishpatra.org \
--cc=jolsa@kernel.org \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=zhouquan@iscas.ac.cn \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).