mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tianyi Liu <i.pear@outlook.com>
To: mlevitsk@redhat.com
Cc: acme@kernel.org, adrian.hunter@intel.com,
	alexander.shishkin@linux.intel.com, i.pear@outlook.com,
	irogers@google.com, jolsa@kernel.org, kvm@vger.kernel.org,
	kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	mark.rutland@arm.com, mingo@redhat.com, namhyung@kernel.org,
	pbonzini@redhat.com, peterz@infradead.org, seanjc@google.com,
	x86@kernel.org
Subject: Re: [PATCH v2 4/5] perf kvm: Support sampling guest callchains
Date: Wed, 11 Oct 2023 22:44:55 +0800	[thread overview]
Message-ID: <SY4P282MB1084293EB22AB6FBF72DA0599DCCA@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <ce964b43f926708f30c85640591b2fc62397b719.camel@redhat.com>

Hi Maxim,

At 2023-10-10 16:12 +0000, Maxim Levitsky wrote:
> > +static inline void
> > +perf_callchain_guest32(struct perf_callchain_entry_ctx *entry)
> > +{
> > +	struct stack_frame_ia32 frame;
> > +	const struct stack_frame_ia32 *fp;
> > +
> > +	fp = (void *)perf_guest_get_frame_pointer();
> > +	while (fp && entry->nr < entry->max_stack) {
> > +		if (!perf_guest_read_virt(&fp->next_frame, &frame.next_frame,
> This should be fp->next_frame.
> > +			sizeof(frame.next_frame)))
> > +			break;
> > +		if (!perf_guest_read_virt(&fp->return_address, &frame.return_address,
> Same here.
> > +			sizeof(frame.return_address)))
> > +			break;
> > +		perf_callchain_store(entry, frame.return_address);
> > +		fp = (void *)frame.next_frame;
> > +	}
> > +}
> > +

The address space where `fp` resides here is in the guest memory, not in
the directly accessible kernel address space. `&fp->next_frame` and
`&fp->return_address` are simply calculating address offsets in a more
readable manner, much like `fp + 0` and `fp + 4`.

The original implementation of `perf_callchain_user` and
`perf_callchain_user32` also use this approach [1].

>
> For symmetry, maybe it makes sense to have perf_callchain_guest32 and perf_callchain_guest64
> and then make perf_callchain_guest call each? No strong opinion on this of course.
>

The `perf_callchain_guest` and `perf_callchain_guest32` here are simply
designed to mimic `perf_callchain_user` and `perf_callchain_user32` [2].
I'm also open to make the logic fully separate, if this doesn't seem
elegant enough.

[1] https://github.com/torvalds/linux/blob/master/arch/x86/events/core.c#L2890
[2] https://github.com/torvalds/linux/blob/master/arch/x86/events/core.c#L2820


Best regards,
Tianyi Liu

  reply	other threads:[~2023-10-11 14:46 UTC|newest]

Thread overview: 18+ 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: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:32   ` kernel test robot
2023-10-08 22:25   ` kernel test robot
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:56 ` [PATCH v2 3/5] KVM: implement new perf interfaces Tianyi Liu
2023-10-08 14:57 ` [PATCH v2 4/5] perf kvm: Support sampling guest callchains Tianyi Liu
2023-10-08 19:57   ` kernel test robot
2023-10-10 16:12   ` Maxim Levitsky
2023-10-11 14:44     ` Tianyi Liu [this message]
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-11 16:45 ` [PATCH v2 0/5] perf: KVM: Enable callchains for guests Marc Zyngier
2023-10-12  6:35   ` Tianyi Liu
2023-10-13 14:01     ` Mark Rutland
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=SY4P282MB1084293EB22AB6FBF72DA0599DCCA@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=mlevitsk@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: 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

all inboxes | Powered by JetHome®