From: "Jin, Yao" <yao.jin@linux.intel.com>
To: peterz@infradead.org
Cc: mingo@redhat.com, oleg@redhat.com, acme@kernel.org,
jolsa@kernel.org, Linux-kernel@vger.kernel.org,
ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com,
alexander.shishkin@linux.intel.com, mark.rutland@arm.com
Subject: Re: [PATCH v1 2/2] perf/core: Fake regs for leaked kernel samples
Date: Mon, 10 Aug 2020 10:03:18 +0800 [thread overview]
Message-ID: <c7f02b26-3417-c692-5f03-120642bf8910@linux.intel.com> (raw)
In-Reply-To: <20200807090232.GE2674@hirez.programming.kicks-ass.net>
Hi Peter,
On 8/7/2020 5:02 PM, peterz@infradead.org wrote:
> On Fri, Aug 07, 2020 at 02:24:30PM +0800, Jin, Yao wrote:
>> Hi Peter,
>>
>> On 8/6/2020 7:00 PM, peterz@infradead.org wrote:
>>> On Thu, Aug 06, 2020 at 11:18:27AM +0200, peterz@infradead.org wrote:
>>>
>>>> Suppose we have nested virt:
>>>>
>>>> L0-hv
>>>> |
>>>> G0/L1-hv
>>>> |
>>>> G1
>>>>
>>>> And we're running in G0, then:
>>>>
>>>> - 'exclude_hv' would exclude L0 events
>>>> - 'exclude_host' would ... exclude L1-hv events?
>>>> - 'exclude_guest' would ... exclude G1 events?
>>>
>>> So in arch/x86/events/intel/core.c we have:
>>>
>>> static inline void intel_set_masks(struct perf_event *event, int idx)
>>> {
>>> struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
>>>
>>> if (event->attr.exclude_host)
>>> __set_bit(idx, (unsigned long *)&cpuc->intel_ctrl_guest_mask);
>>> if (event->attr.exclude_guest)
>>> __set_bit(idx, (unsigned long *)&cpuc->intel_ctrl_host_mask);
>>> if (event_is_checkpointed(event))
>>> __set_bit(idx, (unsigned long *)&cpuc->intel_cp_status);
>>> }
>>>
>>
>> exclude_host is now set by guest (pmc_reprogram_counter,
>> arch/x86/kvm/pmu.c). When enabling the event, we can check exclude_host to
>> know if it's a guest.
>>
>> Otherwise we may need more flags in event->attr to indicate the status.
>>
>>> which is, afaict, just plain wrong. Should that not be something like:
>>>
>>> if (!event->attr.exclude_host)
>>> __set_bit(idx, (unsigned long *)&cpuc->intel_ctrl_host_mask);
>>> if (!event->attr.exclude_guest)
>>> __set_bit(idx, (unsigned long *)&cpuc->intel_ctrl_guest_mask);
>>>
>>>
>>
>> How can we know it's guest or host even if exclude_host is set in guest?
>
> I'm not following you, consider:
>
> xh xg h g h' g'
> 0 0 0 0 1 1
> 0 1 1 0 1 0
> 1 0 0 1 0 1
> 1 1 1 1 0 0
>
>
Thanks for the table! It clearly shows the combinations of different conditions.
My understanding is:
xh = exclude_host
xg = exclude_guest
h = intel_ctrl_host_mask (before)
g = intel_ctrl_guest_mask (before)
h' = intel_ctrl_host_mask (after)
g' = intel_ctrl_guest_mask (after)
For guest, exclude_host = 1 and exclude_guest = 0
xh xg h g h' g'
1 0 0 1 0 1
before/after values are not changed.
For host, exclude_host = 0 and exclude_guest = 1
xh xg h g h' g'
0 1 1 0 1 0
before/after values are not changed.
> So the 0,0 and 1,1 cases get flipped. I have a suspicion, but this
> _really_ should have fat comments all over :-(
>
I'm not very sure about other cases.
xh xg h g h' g'
0 0 0 0 1 1
1 1 1 1 0 0
The before/after values are just reversed. I don't know if there will be some negative impacts?
Maybe we need more reviews here.
> What a sodding trainwreck..
>
:(
Thanks
Jin Yao
next prev parent reply other threads:[~2020-08-10 2:03 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-31 2:56 [PATCH v1 1/2] Missing instruction_pointer_set() instances Jin Yao
2020-07-31 2:56 ` [PATCH v1 2/2] perf/core: Fake regs for leaked kernel samples Jin Yao
2020-08-04 11:49 ` peterz
2020-08-05 2:15 ` Jin, Yao
2020-08-05 12:44 ` peterz
2020-08-05 12:57 ` peterz
2020-08-06 2:26 ` Jin, Yao
2020-08-06 9:18 ` peterz
2020-08-06 9:24 ` peterz
2020-08-07 5:32 ` Jin, Yao
2020-08-06 11:00 ` peterz
2020-08-07 6:24 ` Jin, Yao
2020-08-07 9:02 ` peterz
2020-08-10 2:03 ` Jin, Yao [this message]
2020-08-07 5:23 ` Jin, Yao
2020-08-11 7:50 ` Jin, Yao
2020-08-11 7:59 ` Peter Zijlstra
2020-08-11 8:31 ` Jin, Yao
2020-08-11 8:45 ` Peter Zijlstra
2020-08-12 3:52 ` Jin, Yao
2020-08-12 7:25 ` Like Xu
2020-08-04 11:31 ` [PATCH v1 1/2] Missing instruction_pointer_set() instances peterz
2020-08-05 0:26 ` Jin, Yao
2020-08-04 21:31 ` Max Filippov
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=c7f02b26-3417-c692-5f03-120642bf8910@linux.intel.com \
--to=yao.jin@linux.intel.com \
--cc=Linux-kernel@vger.kernel.org \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@intel.com \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=yao.jin@intel.com \
/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).