linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Cc: kvmarm@lists.linux.dev, iommu@lists.linux.dev,
	 linux-arm-kernel@lists.infradead.org, linuxarm@huawei.com,
	 kevin.tian@intel.com, jgg@ziepe.ca, alex.williamson@redhat.com,
	 maz@kernel.org, oliver.upton@linux.dev, will@kernel.org,
	robin.murphy@arm.com,  jean-philippe@linaro.org,
	jonathan.cameron@huawei.com
Subject: Re: [RFC PATCH v2 1/7] KVM: Add generic infrastructure to support pinned VMIDs
Date: Mon, 24 Jun 2024 08:48:54 -0700	[thread overview]
Message-ID: <ZnmVZo8awnuFdQjz@google.com> (raw)
In-Reply-To: <20240208151837.35068-2-shameerali.kolothum.thodi@huawei.com>

On Thu, Feb 08, 2024, Shameer Kolothum wrote:
> Provide generic helper functions to get/put pinned VMIDs if the arch
> supports it.

IMO, this has no business being in generic KVM.  Multiple architectures have
constructs that are _similar_ ARM's VMID, but AFAICT the exact semantics are very
ARM specific.  I.e. odds are very good that the only thing that can actually use
kvm_pinned_vmid_get() is the SMMU, because the concept won't fit any other
architecture.

The other issue is that other architectures support building KVM as a module,
which makes it much more difficult to guarantee the safety of these hooks.

> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
> ---
>  include/linux/kvm_host.h | 18 ++++++++++++++++++
>  virt/kvm/Kconfig         |  3 +++
>  virt/kvm/kvm_main.c      | 23 +++++++++++++++++++++++
>  3 files changed, 44 insertions(+)
> 
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 7e7fd25b09b3..610e239bea46 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -2311,6 +2311,24 @@ static inline void kvm_handle_signal_exit(struct kvm_vcpu *vcpu)
>  }
>  #endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */
>  
> +#ifdef CONFIG_HAVE_KVM_PINNED_VMID
> +int kvm_arch_pinned_vmid_get(struct kvm *kvm);
> +void kvm_arch_pinned_vmid_put(struct kvm *kvm);
> +#endif
> +
> +#ifdef CONFIG_HAVE_KVM_PINNED_VMID
> +int kvm_pinned_vmid_get(struct kvm *kvm);
> +void kvm_pinned_vmid_put(struct kvm *kvm);
> +#else
> +static inline int kvm_pinned_vmid_get(struct kvm *kvm)
> +{
> +	return -EINVAL;
> +}
> +
> +static inline void kvm_pinned_vmid_put(struct kvm *kvm)
> +{
> +}
> +#endif
>  /*
>   * If more than one page is being (un)accounted, @virt must be the address of
>   * the first page of a block of pages what were allocated together (i.e
> diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig
> index 184dab4ee871..a3052c8e3ac4 100644
> --- a/virt/kvm/Kconfig
> +++ b/virt/kvm/Kconfig
> @@ -108,3 +108,6 @@ config KVM_GENERIC_PRIVATE_MEM
>         select KVM_GENERIC_MEMORY_ATTRIBUTES
>         select KVM_PRIVATE_MEM
>         bool
> +
> +config HAVE_KVM_PINNED_VMID
> +       bool
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 10bfc88a69f7..f84d6da5f464 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -3918,6 +3918,29 @@ bool kvm_vcpu_wake_up(struct kvm_vcpu *vcpu)
>  }
>  EXPORT_SYMBOL_GPL(kvm_vcpu_wake_up);
>  
> +#ifdef CONFIG_HAVE_KVM_PINNED_VMID
> +int kvm_pinned_vmid_get(struct kvm *kvm)
> +{
> +	int ret;
> +
> +	if (!kvm_get_kvm_safe(kvm))
> +		return -ENOENT;
> +	ret  = kvm_arch_pinned_vmid_get(kvm);
> +	if (ret < 0)
> +		kvm_put_kvm(kvm);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(kvm_pinned_vmid_get);
> +
> +void kvm_pinned_vmid_put(struct kvm *kvm)
> +{
> +	kvm_arch_pinned_vmid_put(kvm);
> +	kvm_put_kvm(kvm);
> +}
> +EXPORT_SYMBOL_GPL(kvm_pinned_vmid_put);
> +#endif
> +
>  #ifndef CONFIG_S390
>  /*
>   * Kick a sleeping VCPU, or a guest VCPU in guest mode, into host kernel mode.
> -- 
> 2.34.1
> 


  reply	other threads:[~2024-06-24 15:49 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-08 15:18 [RFC PATCH v2 0/7] iommu/arm-smmu-v3: Use pinned KVM VMID for stage 2 Shameer Kolothum
2024-02-08 15:18 ` [RFC PATCH v2 1/7] KVM: Add generic infrastructure to support pinned VMIDs Shameer Kolothum
2024-06-24 15:48   ` Sean Christopherson [this message]
2024-02-08 15:18 ` [RFC PATCH v2 2/7] KVM: arm64: Introduce support to pin VMIDs Shameer Kolothum
2024-06-24 19:22   ` Oliver Upton
2024-06-24 19:34     ` Shameerali Kolothum Thodi
2024-06-24 19:52       ` Oliver Upton
2024-02-08 15:18 ` [RFC PATCH v2 3/7] KVM: arm64: Add interfaces for pinned VMID support Shameer Kolothum
2024-02-08 15:18 ` [RFC PATCH v2 4/7] iommufd: Associate kvm pointer to iommufd ctx Shameer Kolothum
2024-02-08 15:42   ` Jason Gunthorpe
2024-06-24 16:53     ` Sean Christopherson
2024-06-24 17:07       ` Jason Gunthorpe
2024-06-24 17:54         ` Sean Christopherson
2024-06-24 18:01           ` Jason Gunthorpe
2024-06-24 19:12             ` Oliver Upton
2024-06-24 19:29               ` Sean Christopherson
2024-06-24 19:51                 ` Oliver Upton
2024-06-24 22:35                   ` Jason Gunthorpe
2024-06-25  2:21                 ` Tian, Kevin
2024-06-24 19:13           ` Shameerali Kolothum Thodi
2024-06-25  1:53     ` Tian, Kevin
2024-02-08 15:18 ` [RFC PATCH v2 5/7] iommu: Pass in kvm pointer to domain_alloc_user Shameer Kolothum
2024-02-08 15:43   ` Jason Gunthorpe
2024-02-08 15:18 ` [RFC PATCH v2 6/7] iommu/arm-smmu-v3: Use KVM VMID for s2 stage Shameer Kolothum
2024-02-08 15:59   ` Jason Gunthorpe
2024-02-08 16:14     ` Shameerali Kolothum Thodi
2024-02-08 16:26       ` Jason Gunthorpe
2024-02-08 16:36         ` Shameerali Kolothum Thodi
2024-02-08 15:18 ` [RFC PATCH v2 7/7] iommu/arm-smmu-v3: Enable broadcast TLB maintenance Shameer Kolothum
2024-02-08 15:35 ` [RFC PATCH v2 0/7] iommu/arm-smmu-v3: Use pinned KVM VMID for stage 2 Jason Gunthorpe
2024-02-08 15:49   ` Shameerali Kolothum Thodi
2024-02-08 16:07     ` Jason Gunthorpe
2024-02-09 11:58 ` Jean-Philippe Brucker
2024-02-09 12:48   ` Jason Gunthorpe
2024-02-09 13:54   ` Shameerali Kolothum Thodi

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=ZnmVZo8awnuFdQjz@google.com \
    --to=seanjc@google.com \
    --cc=alex.williamson@redhat.com \
    --cc=iommu@lists.linux.dev \
    --cc=jean-philippe@linaro.org \
    --cc=jgg@ziepe.ca \
    --cc=jonathan.cameron@huawei.com \
    --cc=kevin.tian@intel.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linuxarm@huawei.com \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=robin.murphy@arm.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=will@kernel.org \
    /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).