From: Paolo Bonzini <pbonzini@redhat.com>
To: Like Xu <like.xu.linux@gmail.com>, Jim Mattson <jmattson@google.com>
Cc: Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] KVM: x86/pmu: Refactoring kvm_perf_overflow{_intr}()
Date: Thu, 18 Nov 2021 15:53:30 +0100 [thread overview]
Message-ID: <0008cb01-9100-6664-2cb8-e1c741f69a77@redhat.com> (raw)
In-Reply-To: <20211116122030.4698-5-likexu@tencent.com>
On 11/16/21 13:20, Like Xu wrote:
> - }
> + if (!intr)
> + return;
> +
> + /*
> + * Inject PMI. If vcpu was in a guest mode during NMI PMI
> + * can be ejected on a guest mode re-entry. Otherwise we can't
> + * be sure that vcpu wasn't executing hlt instruction at the
> + * time of vmexit and is not going to re-enter guest mode until
> + * woken up. So we should wake it, but this is impossible from
> + * NMI context. Do it from irq work instead.
> + */
> + if (!kvm_is_in_guest())
> + irq_work_queue(&pmc_to_pmu(pmc)->irq_work);
> + else
> + kvm_make_request(KVM_REQ_PMI, pmc->vcpu);
> +}
> +
> +static void kvm_perf_overflow(struct perf_event *perf_event,
> + struct perf_sample_data *data,
> + struct pt_regs *regs)
> +{
> + struct kvm_pmc *pmc = perf_event->overflow_handler_context;
> + struct kvm_pmu *pmu = pmc_to_pmu(pmc);
> +
> + if (!test_and_set_bit(pmc->idx, pmu->reprogram_pmi))
> + kvm_pmu_counter_overflow(pmc, need_overflow_intr(pmc));
> }
It could be even better to make a single function, but instead of
need_overflow_intr(pmc) you should store into pmc from
pmc_reprogram_counter. Like this:
/* Ignore counters that have been reported already. */
if (test_and_set_bit(pmc->idx, pmu->reprogram_pmi))
return;
__set_bit(pmc->idx, (unsigned long *)&pmu->global_status);
kvm_make_request(KVM_REQ_PMU, pmc->vcpu);
if (pmc->intr) {
/*
* Inject PMI. If vcpu was in a guest mode during NMI PMI
* can be ejected on a guest mode re-entry. Otherwise we can't
* be sure that vcpu wasn't executing hlt instruction at the
* time of vmexit and is not going to re-enter guest mode until
* woken up. So we should wake it, but this is impossible from
* NMI context. Do it from irq work instead.
*/
if (!kvm_is_in_guest())
irq_work_queue(pmu->irq_work);
else
kvm_make_request(KVM_REQ_PMI, pmc->vcpu);
}
Paolo
prev parent reply other threads:[~2021-11-18 14:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-16 12:20 [PATCH 0/4] KVM: x86/pmu: An insightful refactoring of vPMU code Like Xu
2021-11-16 12:20 ` [PATCH 1/4] KVM: x86/pmu: Setup pmc->eventsel for fixed PMCs Like Xu
2021-11-16 12:20 ` [PATCH 2/4] KVM: x86/pmu: Refactoring find_arch_event() to find_perf_hw_id() Like Xu
2021-11-18 13:29 ` Paolo Bonzini
2021-11-16 12:20 ` [PATCH 3/4] KVM: x86/pmu: Reuse find_perf_hw_id() and drop find_fixed_event() Like Xu
2021-11-18 14:43 ` Paolo Bonzini
2021-11-18 15:00 ` Paolo Bonzini
2021-11-19 7:16 ` Like Xu
2021-11-19 10:29 ` Paolo Bonzini
2021-11-19 11:10 ` Like Xu
2021-11-16 12:20 ` [PATCH 4/4] KVM: x86/pmu: Refactoring kvm_perf_overflow{_intr}() Like Xu
2021-11-18 14:53 ` Paolo Bonzini [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=0008cb01-9100-6664-2cb8-e1c741f69a77@redhat.com \
--to=pbonzini@redhat.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=like.xu.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.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).