kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pierre Morel <pmorel@linux.ibm.com>
To: Matthew Rosato <mjrosato@linux.ibm.com>, linux-s390@vger.kernel.org
Cc: alex.williamson@redhat.com, cohuck@redhat.com,
	schnelle@linux.ibm.com, farman@linux.ibm.com,
	borntraeger@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com,
	gerald.schaefer@linux.ibm.com, agordeev@linux.ibm.com,
	svens@linux.ibm.com, frankja@linux.ibm.com, david@redhat.com,
	imbrenda@linux.ibm.com, vneethv@linux.ibm.com,
	oberpar@linux.ibm.com, freude@linux.ibm.com, thuth@redhat.com,
	pasic@linux.ibm.com, pbonzini@redhat.com, corbet@lwn.net,
	jgg@nvidia.com, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH v9 16/21] KVM: s390: pci: add routines to start/stop interpretive execution
Date: Tue, 28 Jun 2022 12:53:32 +0200	[thread overview]
Message-ID: <7a9990ca-b591-1351-8848-8d7c59449b12@linux.ibm.com> (raw)
In-Reply-To: <20220606203325.110625-17-mjrosato@linux.ibm.com>



On 6/6/22 22:33, Matthew Rosato wrote:
> These routines will be invoked at the time an s390x vfio-pci device is
> associated with a KVM (or when the association is removed), allowing
> the zPCI device to enable or disable load/store intepretation mode;
> this requires the host zPCI device to inform firmware of the unique
> token (GISA designation) that is associated with the owning KVM.
> 
> Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
> ---
>   arch/s390/include/asm/kvm_host.h |  18 ++++
>   arch/s390/include/asm/pci.h      |   1 +
>   arch/s390/kvm/kvm-s390.c         |  15 +++
>   arch/s390/kvm/pci.c              | 162 +++++++++++++++++++++++++++++++
>   arch/s390/kvm/pci.h              |   5 +
>   arch/s390/pci/pci.c              |   4 +
>   6 files changed, 205 insertions(+)
> 
> diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
> index 8e381603b6a7..6e83d746bae2 100644
> --- a/arch/s390/include/asm/kvm_host.h
> +++ b/arch/s390/include/asm/kvm_host.h
> @@ -19,6 +19,7 @@
>   #include <linux/kvm.h>
>   #include <linux/seqlock.h>
>   #include <linux/module.h>
> +#include <linux/pci.h>
>   #include <asm/debug.h>
>   #include <asm/cpu.h>
>   #include <asm/fpu/api.h>
> @@ -967,6 +968,8 @@ struct kvm_arch{
>   	DECLARE_BITMAP(idle_mask, KVM_MAX_VCPUS);
>   	struct kvm_s390_gisa_interrupt gisa_int;
>   	struct kvm_s390_pv pv;
> +	struct list_head kzdev_list;
> +	spinlock_t kzdev_list_lock;
>   };
>   
>   #define KVM_HVA_ERR_BAD		(-1UL)
> @@ -1017,4 +1020,19 @@ static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
>   static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
>   static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
>   
> +#define __KVM_HAVE_ARCH_VM_FREE
> +void kvm_arch_free_vm(struct kvm *kvm);
> +
> +#ifdef CONFIG_VFIO_PCI_ZDEV_KVM
> +int kvm_s390_pci_register_kvm(struct zpci_dev *zdev, struct kvm *kvm);
> +void kvm_s390_pci_unregister_kvm(struct zpci_dev *zdev);
> +#else
> +static inline int kvm_s390_pci_register_kvm(struct zpci_dev *dev,
> +					    struct kvm *kvm)
> +{
> +	return -EPERM;
> +}
> +static inline void kvm_s390_pci_unregister_kvm(struct zpci_dev *dev) {}
> +#endif
> +
>   #endif
> diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h
> index 322060a75d9f..85eb0ef9d4c3 100644
> --- a/arch/s390/include/asm/pci.h
> +++ b/arch/s390/include/asm/pci.h
> @@ -194,6 +194,7 @@ struct zpci_dev {
>   	/* IOMMU and passthrough */
>   	struct s390_domain *s390_domain; /* s390 IOMMU domain data */
>   	struct kvm_zdev *kzdev;
> +	struct mutex kzdev_lock;

I guess that since it did not exist before the lock is not there to 
protect the zpci_dev struct.
May be add a comment to say what it is protecting.


>   };
>   
>   static inline bool zdev_enabled(struct zpci_dev *zdev)
> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index a66da3f66114..4758bb731199 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
> @@ -2790,6 +2790,14 @@ static void sca_dispose(struct kvm *kvm)
>   	kvm->arch.sca = NULL;
>   }
>   
> +void kvm_arch_free_vm(struct kvm *kvm)
> +{
> +	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM))
> +		kvm_s390_pci_clear_list(kvm);
> +
> +	__kvm_arch_free_vm(kvm);
> +}
> +
>   int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
>   {
>   	gfp_t alloc_flags = GFP_KERNEL_ACCOUNT;
> @@ -2872,6 +2880,13 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
>   
>   	kvm_s390_crypto_init(kvm);
>   
> +	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM)) {
> +		mutex_lock(&kvm->lock);
> +		kvm_s390_pci_init_list(kvm);
> +		kvm_s390_vcpu_pci_enable_interp(kvm);
> +		mutex_unlock(&kvm->lock);
> +	}
> +
>   	mutex_init(&kvm->arch.float_int.ais_lock);
>   	spin_lock_init(&kvm->arch.float_int.lock);
>   	for (i = 0; i < FIRQ_LIST_COUNT; i++)
> diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
> index b232c8cbaa81..24211741deb0 100644
> --- a/arch/s390/kvm/pci.c
> +++ b/arch/s390/kvm/pci.c
> @@ -12,7 +12,9 @@
>   #include <asm/pci.h>
>   #include <asm/pci_insn.h>
>   #include <asm/pci_io.h>
> +#include <asm/sclp.h>
>   #include "pci.h"
> +#include "kvm-s390.h"
>   
>   struct zpci_aift *aift;
>   
> @@ -423,6 +425,166 @@ static void kvm_s390_pci_dev_release(struct zpci_dev *zdev)
>   	kfree(kzdev);
>   }
>   
> +
> +/*
> + * Register device with the specified KVM. If interpetation facilities are
> + * available, enable them and let userspace indicate whether or not they will
> + * be used (specify SHM bit to disable).
> + */
> +int kvm_s390_pci_register_kvm(struct zpci_dev *zdev, struct kvm *kvm)
> +{
> +	int rc;
> +
> +	if (!zdev)
> +		return -EINVAL;
> +
> +	mutex_lock(&zdev->kzdev_lock);
> +
> +	if (zdev->kzdev || zdev->gisa != 0 || !kvm) {
> +		mutex_unlock(&zdev->kzdev_lock);
> +		return -EINVAL;
> +	}
> +
> +	kvm_get_kvm(kvm);
> +
> +	mutex_lock(&kvm->lock);

Why do we need to lock KVM here?

just a question, I do not think it is a big problem.

> +
> +	rc = kvm_s390_pci_dev_open(zdev);
> +	if (rc)
> +		goto err;
> +
> +	/*
> +	 * If interpretation facilities aren't available, add the device to
> +	 * the kzdev list but don't enable for interpretation.
> +	 */
> +	if (!kvm_s390_pci_interp_allowed())
> +		goto out;
> +
> +	/*
> +	 * If this is the first request to use an interpreted device, make the
> +	 * necessary vcpu changes
> +	 */
> +	if (!kvm->arch.use_zpci_interp)
> +		kvm_s390_vcpu_pci_enable_interp(kvm);
> +
> +	if (zdev_enabled(zdev)) {
> +		rc = zpci_disable_device(zdev);
> +		if (rc)
> +			goto err;
> +	}
> +
> +	/*
> +	 * Store information about the identity of the kvm guest allowed to
> +	 * access this device via interpretation to be used by host CLP
> +	 */
> +	zdev->gisa = (u32)virt_to_phys(&kvm->arch.sie_page2->gisa);
> +
> +	rc = zpci_enable_device(zdev);
> +	if (rc)
> +		goto clear_gisa;
> +
> +	/* Re-register the IOMMU that was already created */
> +	rc = zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma,
> +				virt_to_phys(zdev->dma_table));
> +	if (rc)
> +		goto clear_gisa;
> +
> +out:
> +	zdev->kzdev->kvm = kvm;
> +
> +	spin_lock(&kvm->arch.kzdev_list_lock);
> +	list_add_tail(&zdev->kzdev->entry, &kvm->arch.kzdev_list);
> +	spin_unlock(&kvm->arch.kzdev_list_lock);
> +
> +	mutex_unlock(&kvm->lock);
> +	mutex_unlock(&zdev->kzdev_lock);
> +	return 0;
> +
> +clear_gisa:
> +	zdev->gisa = 0;
> +err:
> +	if (zdev->kzdev)
> +		kvm_s390_pci_dev_release(zdev);
> +	mutex_unlock(&kvm->lock);
> +	mutex_unlock(&zdev->kzdev_lock);
> +	kvm_put_kvm(kvm);
> +	return rc;
> +}
> +EXPORT_SYMBOL_GPL(kvm_s390_pci_register_kvm);
> +
> +void kvm_s390_pci_unregister_kvm(struct zpci_dev *zdev)
> +{
> +	struct kvm *kvm;
> +
> +	if (!zdev)
> +		return;
> +
> +	mutex_lock(&zdev->kzdev_lock);
> +
> +	if (WARN_ON(!zdev->kzdev)) {

When can this happen ?

> +		mutex_unlock(&zdev->kzdev_lock);
> +		return;
> +	}
> +
> +	kvm = zdev->kzdev->kvm;
> +	mutex_lock(&kvm->lock);
> +
> +	/*
> +	 * A 0 gisa means interpretation was never enabled, just remove the
> +	 * device from the list.
> +	 */
> +	if (zdev->gisa == 0)
> +		goto out;
> +
> +	/* Forwarding must be turned off before interpretation */
> +	if (zdev->kzdev->fib.fmt0.aibv != 0)
> +		kvm_s390_pci_aif_disable(zdev, true);
> +
> +	/* Remove the host CLP guest designation */
> +	zdev->gisa = 0;
> +
> +	if (zdev_enabled(zdev)) {
> +		if (zpci_disable_device(zdev))
> +			goto out;

NIT debug trace ?

> +	}
> +
> +	if (zpci_enable_device(zdev))
> +		goto out;

NIT debug trace?

Only some questions, otherwise, LGTM

Acked-by: Pierre Morel <pmorel@linux.ibm.com>

-- 
Pierre Morel
IBM Lab Boeblingen

  reply	other threads:[~2022-06-28 10:49 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-06 20:33 [PATCH v9 00/21] KVM: s390: enable zPCI for interpretive execution Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 01/21] s390/sclp: detect the zPCI load/store interpretation facility Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 02/21] s390/sclp: detect the AISII facility Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 03/21] s390/sclp: detect the AENI facility Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 04/21] s390/sclp: detect the AISI facility Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 05/21] s390/airq: pass more TPI info to airq handlers Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 06/21] s390/airq: allow for airq structure that uses an input vector Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 07/21] s390/pci: externalize the SIC operation controls and routine Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 08/21] s390/pci: stash associated GISA designation Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 09/21] s390/pci: stash dtsm and maxstbl Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 10/21] vfio/pci: introduce CONFIG_VFIO_PCI_ZDEV_KVM Matthew Rosato
2022-06-08  6:19   ` Thomas Huth
2022-06-08 13:15     ` Matthew Rosato
2022-06-14  8:56       ` Pierre Morel
2022-06-17 16:15         ` Thomas Huth
2022-06-28 14:58   ` Alex Williamson
2022-06-06 20:33 ` [PATCH v9 11/21] KVM: s390: pci: add basic kvm_zdev structure Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 12/21] KVM: s390: pci: do initial setup for AEN interpretation Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 13/21] KVM: s390: pci: enable host forwarding of Adapter Event Notifications Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 14/21] KVM: s390: mechanism to enable guest zPCI Interpretation Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 15/21] KVM: s390: pci: provide routines for enabling/disabling interrupt forwarding Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 16/21] KVM: s390: pci: add routines to start/stop interpretive execution Matthew Rosato
2022-06-28 10:53   ` Pierre Morel [this message]
2022-06-28 13:27     ` Matthew Rosato
2022-06-06 20:33 ` [PATCH v9 17/21] vfio-pci/zdev: add open/close device hooks Matthew Rosato
2022-06-28 11:22   ` Pierre Morel
2022-06-28 14:59   ` Alex Williamson
2022-06-06 20:33 ` [PATCH v9 18/21] vfio-pci/zdev: add function handle to clp base capability Matthew Rosato
2022-06-28 14:59   ` Alex Williamson
2022-06-06 20:33 ` [PATCH v9 19/21] vfio-pci/zdev: different maxstbl for interpreted devices Matthew Rosato
2022-06-28 15:00   ` Alex Williamson
2022-06-06 20:33 ` [PATCH v9 20/21] KVM: s390: add KVM_S390_ZPCI_OP to manage guest zPCI devices Matthew Rosato
2022-06-08  6:00   ` Thomas Huth
2022-06-14  8:49   ` Pierre Morel
2022-06-06 20:33 ` [PATCH v9 21/21] MAINTAINERS: additional files related kvm s390 pci passthrough Matthew Rosato
2022-06-08  6:02   ` Thomas Huth
2022-06-06 20:42 ` [PATCH v9 00/21] KVM: s390: enable zPCI for interpretive execution Matthew Rosato
2022-06-27 20:57 ` Matthew Rosato
2022-06-28 12:35   ` Christian Borntraeger
2022-06-28 13:40     ` Matthew Rosato
2022-06-28 13:49       ` Jason Gunthorpe
2022-06-28 14:02       ` Christian Borntraeger
2022-07-08 11:33 ` Christian Borntraeger

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=7a9990ca-b591-1351-8848-8d7c59449b12@linux.ibm.com \
    --to=pmorel@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=alex.williamson@redhat.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=corbet@lwn.net \
    --cc=david@redhat.com \
    --cc=farman@linux.ibm.com \
    --cc=frankja@linux.ibm.com \
    --cc=freude@linux.ibm.com \
    --cc=gerald.schaefer@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=jgg@nvidia.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjrosato@linux.ibm.com \
    --cc=oberpar@linux.ibm.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=schnelle@linux.ibm.com \
    --cc=svens@linux.ibm.com \
    --cc=thuth@redhat.com \
    --cc=vneethv@linux.ibm.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).