All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Hao Peng <flyingpenghao@gmail.com>
Cc: pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH ] kvm: x86: Reduce unnecessary function call
Date: Fri, 7 Oct 2022 17:04:26 +0000	[thread overview]
Message-ID: <Y0BcGnabCp9ukxDs@google.com> (raw)
In-Reply-To: <CAPm50aK9oe-m5QWfrFjzGx_vvNveA+U6-Fs3KD5+Zq5RZ+UhDg@mail.gmail.com>

On Fri, Oct 07, 2022, Hao Peng wrote:
> From: Peng Hao <flyingpeng@tencent.com>
> 
> kvm->lock is held very close to mutex_is_locked(kvm->lock).
> Do not need to call mutex_is_locked.
> 
> Signed-off-by: Peng Hao <flyingpeng@tencent.com>
> ---
>  arch/x86/kvm/pmu.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index 02f9e4f245bd..8a7dbe2c469a 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -601,8 +601,7 @@ int kvm_vm_ioctl_set_pmu_event_filter(struct kvm
> *kvm, void __user *argp)
>         sort(&filter->events, filter->nevents, sizeof(__u64), cmp_u64, NULL);
> 
>         mutex_lock(&kvm->lock);
> -       filter = rcu_replace_pointer(kvm->arch.pmu_event_filter, filter,
> -                                    mutex_is_locked(&kvm->lock));
> +       filter = rcu_replace_pointer(kvm->arch.pmu_event_filter, filter, 1);

I'd prefer to keep the mutex_is_locked() call, even though it's quite silly, as
it self-documents what is being used to protect writes to pmu_event_filter.
The third paramter is evaluated iff CONFIG_PROVE_RCU=y, which is the complete
oppositive of performance sensitive, so in practice there's no real downside to
the somewhat superfluous call.

>         mutex_unlock(&kvm->lock);
> 
>         synchronize_srcu_expedited(&kvm->srcu);
> --
> 2.27.0

      reply	other threads:[~2022-10-07 17:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-07 15:58 [PATCH ] kvm: x86: Reduce unnecessary function call Hao Peng
2022-10-07 17:04 ` Sean Christopherson [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=Y0BcGnabCp9ukxDs@google.com \
    --to=seanjc@google.com \
    --cc=flyingpenghao@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.