mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: Ackerley Tng <ackerleytng@google.com>,
	Fuad Tabba <tabba@google.com>,
	Binbin Wu <binbin.wu@linux.intel.com>,
	Shivank Garg <shivankg@amd.com>, Yan Zhao <yan.y.zhao@intel.com>,
	Sean Christopherson <seanjc@google.com>
Subject: Re: [PATCH 3/3] KVM: always make in-place conversion a compile-time constant when possible
Date: Wed, 21 Oct 2026 15:07:16 +0800	[thread overview]
Message-ID: <4217cec4-2988-41a9-b6de-cce0708ec830@intel.com> (raw)
In-Reply-To: <20261020131447.122096-4-pbonzini@redhat.com>

On 10/20/2026 9:14 PM, Paolo Bonzini wrote:
> Remove the unnecessary static call indirection and make
> gmem_in_place_conversion a constant if CONFIG_KVM_PRIVATE_MEMATTR_VM
> is false.
> 
> Require that CONFIG_KVM_PRIVATE_MEMATTR_VM is y only if
> kvm_arch_has_private_mem is also defined.  

This reads like the patch is going to make such a requirement. However, it doesn't.

> This way, the three
> possible cases can be expressed without nested #ifs.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>

> ---
>  include/linux/kvm_host.h | 13 +++++--------
>  virt/kvm/kvm_main.c      | 13 +++++++------
>  2 files changed, 12 insertions(+), 14 deletions(-)
> 
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 09c57d31d153..e7fc94e2910a 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -2585,15 +2585,7 @@ bool kvm_arch_post_set_vm_memory_attributes(struct kvm *kvm,
>  #endif  /* CONFIG_KVM_VM_MEMORY_ATTRIBUTES */
>  
>  #ifdef CONFIG_KVM_PRIVATE_MEMATTR_VM
> -static inline bool kvm_vm_is_private_gfn(struct kvm *kvm, gfn_t gfn)
> -{
> -	return kvm_get_vm_memory_attributes(kvm, gfn) & KVM_MEMORY_ATTRIBUTE_PRIVATE;
> -}
> -#endif  /* CONFIG_KVM_PRIVATE_MEMATTR_VM */
> -
> -#ifdef kvm_arch_has_private_mem
>  extern bool gmem_in_place_conversion;
> -
>  typedef bool (kvm_is_private_gfn_t)(struct kvm *kvm, gfn_t gfn);
>  DECLARE_STATIC_CALL(__kvm_is_private_gfn, kvm_is_private_gfn_t);
>  
> @@ -2601,6 +2593,11 @@ static inline bool kvm_is_private_gfn(struct kvm *kvm, gfn_t gfn)
>  {
>  	return static_call(__kvm_is_private_gfn)(kvm, gfn);
>  }
> +
> +#elif defined kvm_arch_has_private_mem
> +#define gmem_in_place_conversion true
> +#define kvm_is_private_gfn kvm_gmem_is_private_gfn
> +
>  #else
>  #define gmem_in_place_conversion false
>  
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 3e35766f5c7e..a356a29be985 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -104,11 +104,9 @@ EXPORT_SYMBOL_FOR_KVM_INTERNAL(halt_poll_ns_shrink);
>  static bool __ro_after_init allow_unsafe_mappings;
>  module_param(allow_unsafe_mappings, bool, 0444);
>  
> -#ifdef kvm_arch_has_private_mem
> -bool __ro_after_init gmem_in_place_conversion = !IS_ENABLED(CONFIG_KVM_PRIVATE_MEMATTR_VM);
>  #ifdef CONFIG_KVM_PRIVATE_MEMATTR_VM
> +bool __ro_after_init gmem_in_place_conversion = false;
>  module_param(gmem_in_place_conversion, bool, 0444);
> -#endif
>  EXPORT_SYMBOL_FOR_KVM_INTERNAL(gmem_in_place_conversion);
>  #endif
>  
> @@ -2705,18 +2703,21 @@ static int kvm_vm_ioctl_set_mem_attributes(struct kvm *kvm,
>  }
>  #endif /* CONFIG_KVM_VM_MEMORY_ATTRIBUTES */
>  
> -#ifdef kvm_arch_has_private_mem
> +#ifdef CONFIG_KVM_PRIVATE_MEMATTR_VM
>  DEFINE_STATIC_CALL_RET0(__kvm_is_private_gfn, kvm_is_private_gfn_t);
>  EXPORT_STATIC_CALL_GPL(__kvm_is_private_gfn);
>  
> +static bool kvm_vm_is_private_gfn(struct kvm *kvm, gfn_t gfn)
> +{
> +	return kvm_get_vm_memory_attributes(kvm, gfn) & KVM_MEMORY_ATTRIBUTE_PRIVATE;
> +}
> +
>  static void kvm_init_memory_attributes(void)
>  {
>  	if (gmem_in_place_conversion)
>  		static_call_update(__kvm_is_private_gfn, kvm_gmem_is_private_gfn);
> -#ifdef CONFIG_KVM_PRIVATE_MEMATTR_VM
>  	else
>  		static_call_update(__kvm_is_private_gfn, kvm_vm_is_private_gfn);
> -#endif
>  }
>  #else
>  static void kvm_init_memory_attributes(void) { }


  reply	other threads:[~2026-10-21  7:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 13:14 [PATCH 0/3] KVM: Kconfig fixes for the VM-wide private memory attribute Paolo Bonzini
2026-10-20 13:14 ` [PATCH 1/3] KVM: split CONFIG_KVM_PRIVATE_MEMATTR_VM out of KVM_VM_MEMORY_ATTRIBUTES Paolo Bonzini
2026-10-21  7:01   ` Xiaoyao Li
2026-10-20 13:14 ` [PATCH 2/3] KVM: x86: leave the legacy private attribute in for TDX and SEV Paolo Bonzini
2026-10-21  7:05   ` Xiaoyao Li
2026-10-20 13:14 ` [PATCH 3/3] KVM: always make in-place conversion a compile-time constant when possible Paolo Bonzini
2026-10-21  7:07   ` Xiaoyao Li [this message]
2026-10-21  7:12     ` Paolo Bonzini
2026-10-21  4:57 ` [PATCH 0/3] KVM: Kconfig fixes for the VM-wide private memory attribute Sean Christopherson

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=4217cec4-2988-41a9-b6de-cce0708ec830@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=ackerleytng@google.com \
    --cc=binbin.wu@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=shivankg@amd.com \
    --cc=tabba@google.com \
    --cc=yan.y.zhao@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

all inboxes | Powered by JetHome®