All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Wei Wang <wei.w.wang@intel.com>
Cc: pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v1] KVM: x86: Introduce macros to simplify KVM_X86_OPS static calls
Date: Wed, 17 Apr 2024 09:26:40 -0700	[thread overview]
Message-ID: <Zh_4QN7eFxyu9hgA@google.com> (raw)
In-Reply-To: <20240417150354.275353-1-wei.w.wang@intel.com>

On Wed, Apr 17, 2024, Wei Wang wrote:
> Introduces two new macros, KVM_X86_SC() and KVM_X86_SCC(), to streamline
> the usage of KVM_X86_OPS static calls. The current implementation of these
> calls is verbose and can lead to alignment challenges due to the two pairs
> of parentheses. This makes the code susceptible to exceeding the "80
> columns per single line of code" limit as defined in the coding-style
> document. The two macros are added to improve code readability and
> maintainability, while adhering to the coding style guidelines.

Heh, I've considered something similar on multiple occasionsi.  Not because
the verbosity bothers me, but because I often search for exact "word" matches
when looking for function usage and the kvm_x86_ prefix trips me up.
 
> Please note that this RFC only updated a few callsites for demonstration
> purposes. If the approach looks good, all callsites will be updated in
> the next version.
> 
> Signed-off-by: Wei Wang <wei.w.wang@intel.com>
> ---
>  arch/x86/include/asm/kvm_host.h |  3 +++
>  arch/x86/kvm/lapic.c            | 15 ++++++++-------
>  arch/x86/kvm/trace.h            |  3 ++-
>  arch/x86/kvm/x86.c              |  8 ++++----
>  4 files changed, 17 insertions(+), 12 deletions(-)
> 
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 6efd1497b026..42f6450c10ec 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -1856,6 +1856,9 @@ extern struct kvm_x86_ops kvm_x86_ops;
>  	DECLARE_STATIC_CALL(kvm_x86_##func, *(((struct kvm_x86_ops *)0)->func));
>  #define KVM_X86_OP_OPTIONAL KVM_X86_OP
>  #define KVM_X86_OP_OPTIONAL_RET0 KVM_X86_OP
> +
> +#define KVM_X86_SC(func, ...) static_call(kvm_x86_##func)(__VA_ARGS__)
> +#define KVM_X86_SCC(func, ...) static_call_cond(kvm_x86_##func)(__VA_ARGS__)

IIRC, static_call_cond() is essentially dead code, i.e. it's the exact same as
static_call().  I believe there's details buried in a proposed series to remove
it[*].  And to not lead things astray, I verified that invoking a NULL kvm_x86_op
with static_call() does no harm (well, doesn't explode at least).

So if we add wrapper macros, I would be in favor in removing all static_call_cond()
as a prep patch so that we can have a single macro.  kvm_ops_update() already WARNs
if a mandatory hook isn't defined, so doing more checks at runtime wouldn't provide
any value.

As for the name, what about KVM_X86_CALL() instead of KVM_X86_SC()?  Two extra
characters, but should make it much more obvious what's going on for readers that
aren't familiar with the infrastructure.

And I bet we can get away with KVM_PMU_CALL() for the PMU hooks.

[*] https://lore.kernel.org/all/cover.1679456900.git.jpoimboe@kernel.org

  reply	other threads:[~2024-04-17 16:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17 15:03 [RFC PATCH v1] KVM: x86: Introduce macros to simplify KVM_X86_OPS static calls Wei Wang
2024-04-17 16:26 ` Sean Christopherson [this message]
2024-04-18  3:57   ` Wang, Wei W
2024-04-18 13:58     ` Sean Christopherson
2024-04-18 14:20       ` Wang, Wei W
2024-04-18 15:22         ` Wang, Wei W

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=Zh_4QN7eFxyu9hgA@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=wei.w.wang@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 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.