From: Shaoqin Huang <shahuang@redhat.com>
To: Sebastian Ott <sebott@redhat.com>
Cc: qemu-arm@nongnu.org, eric.auger@redhat.com,
Paolo Bonzini <pbonzini@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
kvm@vger.kernel.org, qemu-devel@nongnu.org
Subject: Re: [PATCH v1] arm/kvm: Enable support for KVM_ARM_VCPU_PMU_V3_FILTER
Date: Thu, 16 Nov 2023 17:34:28 +0800 [thread overview]
Message-ID: <eb794c0d-51c8-ecbd-2b24-d93ae00466a0@redhat.com> (raw)
In-Reply-To: <3a570842-aaec-6447-b043-d908e83717ec@redhat.com>
Hi Sebastian,
On 11/15/23 20:17, Sebastian Ott wrote:
> Hi,
>
> On Mon, 13 Nov 2023, Shaoqin Huang wrote:
>> + ``pmu-filter={A,D}:start-end[;...]``
>> + KVM implements pmu event filtering to prevent a guest from
>> being able to
>> + sample certain events. It has the following format:
>> +
>> + pmu-filter="{A,D}:start-end[;{A,D}:start-end...]"
>> +
>> + The A means "allow" and D means "deny", start if the first event
>> of the
> ^
> is
>
Thanks for point it out.
> Also it should be stated that the first filter action defines if the whole
> list is an allow or a deny list.
>
>> +static void kvm_arm_pmu_filter_init(CPUState *cs)
>> +{
>> + struct kvm_pmu_event_filter filter;
>> + struct kvm_device_attr attr = {
>> + .group = KVM_ARM_VCPU_PMU_V3_CTRL,
>> + .attr = KVM_ARM_VCPU_PMU_V3_FILTER,
>> + };
>> + KVMState *kvm_state = cs->kvm_state;
>> + char *tmp;
>> + char *str, act;
>> +
>> + if (!kvm_state->kvm_pmu_filter)
>> + return;
>> +
>> + tmp = g_strdup(kvm_state->kvm_pmu_filter);
>> +
>> + for (str = strtok(tmp, ";"); str != NULL; str = strtok(NULL, ";")) {
>> + unsigned short start = 0, end = 0;
>> +
>> + sscanf(str, "%c:%hx-%hx", &act, &start, &end);
>> + if ((act != 'A' && act != 'D') || (!start && !end)) {
>> + error_report("skipping invalid filter %s\n", str);
>> + continue;
>> + }
>> +
>> + filter = (struct kvm_pmu_event_filter) {
>> + .base_event = start,
>> + .nevents = end - start + 1,
>> + .action = act == 'A' ? KVM_PMU_EVENT_ALLOW :
>> + KVM_PMU_EVENT_DENY,
>> + };
>> +
>> + attr.addr = (uint64_t)&filter;
>
> That could move to the initialization of attr (the address of filter
> doesn't change).
>
It looks better. Will change it.
>> + if (!kvm_arm_set_device_attr(cs, &attr, "PMU Event Filter")) {
>> + error_report("Failed to init PMU Event Filter\n");
>> + abort();
>> + }
>> + }
>> +
>> + g_free(tmp);
>> +}
>> +
>> void kvm_arm_pmu_init(CPUState *cs)
>> {
>> struct kvm_device_attr attr = {
>> .group = KVM_ARM_VCPU_PMU_V3_CTRL,
>> .attr = KVM_ARM_VCPU_PMU_V3_INIT,
>> };
>> + static bool pmu_filter_init = false;
>>
>> if (!ARM_CPU(cs)->has_pmu) {
>> return;
>> }
>> + if (!pmu_filter_init) {
>> + kvm_arm_pmu_filter_init(cs);
>> + pmu_filter_init = true;
>
> pmu_filter_init could move inside kvm_arm_pmu_filter_init() - maybe
> together with a comment that this only needs to be called for 1 vcpu.
Good idea. Will do that.
Thanks,
Shaoqin
>
> Thanks,
> Sebastian
>
prev parent reply other threads:[~2023-11-16 9:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-13 8:17 [PATCH v1] arm/kvm: Enable support for KVM_ARM_VCPU_PMU_V3_FILTER Shaoqin Huang
2023-11-15 12:17 ` Sebastian Ott
2023-11-16 9:34 ` Shaoqin Huang [this message]
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=eb794c0d-51c8-ecbd-2b24-d93ae00466a0@redhat.com \
--to=shahuang@redhat.com \
--cc=eric.auger@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=sebott@redhat.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).