public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: "Cédric Le Goater" <clg@kaod.org>
Cc: kvm-ppc@vger.kernel.org, Paul Mackerras <paulus@samba.org>,
	kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH 1/2] KVM: introduce a 'release' method for KVM devices
Date: Fri, 12 Apr 2019 16:32:24 +1000	[thread overview]
Message-ID: <20190412063224.GG8005@umbus.fritz.box> (raw)
In-Reply-To: <20190411135302.27509-2-clg@kaod.org>

[-- Attachment #1: Type: text/plain, Size: 2820 bytes --]

On Thu, Apr 11, 2019 at 03:53:01PM +0200, Cédric Le Goater wrote:
> When a P9 sPAPR VM boots, the CAS negotiation process determines which
> interrupt mode to use (XICS legacy or XIVE native) and invokes a
> machine reset to activate the chosen mode.
> 
> To be able to switch from one interrupt mode to another, we introduce
> the capability to release a KVM device without destroying the VM. The
> KVM device interface is extended with a new 'release' method which is
> called when the file descriptor of the device is closed.
> 
> Once 'release' is called, the 'destroy' method will not be called
> anymore as the device is removed from the device list of the VM.
> 
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Cédric Le Goater <clg@kaod.org>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

Kind of a hack, but a better way to solve this that doesn't involve
inordinate amounts of work doesn't occur to me.

> ---
>  include/linux/kvm_host.h |  9 +++++++++
>  virt/kvm/kvm_main.c      | 13 +++++++++++++
>  2 files changed, 22 insertions(+)
> 
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 831d963451d8..722692e2f745 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -1240,6 +1240,15 @@ struct kvm_device_ops {
>  	 */
>  	void (*destroy)(struct kvm_device *dev);
>  
> +	/*
> +	 * Release is an alternative method to free the device. It is
> +	 * called when the device file descriptor is closed. Once
> +	 * release is called, the destroy method will not be called
> +	 * anymore as the device is removed from the device list of
> +	 * the VM. kvm->lock is held.
> +	 */
> +	void (*release)(struct kvm_device *dev);
> +
>  	int (*set_attr)(struct kvm_device *dev, struct kvm_device_attr *attr);
>  	int (*get_attr)(struct kvm_device *dev, struct kvm_device_attr *attr);
>  	int (*has_attr)(struct kvm_device *dev, struct kvm_device_attr *attr);
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index ea2018ae1cd7..ea2619d5ca98 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2938,6 +2938,19 @@ static int kvm_device_release(struct inode *inode, struct file *filp)
>  	struct kvm_device *dev = filp->private_data;
>  	struct kvm *kvm = dev->kvm;
>  
> +	if (!dev)
> +		return -ENODEV;
> +
> +	if (dev->kvm != kvm)
> +		return -EPERM;
> +
> +	if (dev->ops->release) {
> +		mutex_lock(&kvm->lock);
> +		list_del(&dev->vm_node);
> +		dev->ops->release(dev);
> +		mutex_unlock(&kvm->lock);
> +	}
> +
>  	kvm_put_kvm(kvm);
>  	return 0;
>  }

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2019-04-12  6:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-11 13:53 [PATCH 0/2] KVM: PPC: Book3S HV: add XIVE native exploitation mode (v5 errata) Cédric Le Goater
2019-04-11 13:53 ` [PATCH 1/2] KVM: introduce a 'release' method for KVM devices Cédric Le Goater
2019-04-12  6:32   ` David Gibson [this message]
2019-04-11 13:53 ` [PATCH 2/2] KVM: PPC: Book3S HV: XIVE: replace the 'destroy' method by 'release' Cédric Le Goater
2019-04-12  6:34   ` David Gibson

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=20190412063224.GG8005@umbus.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=clg@kaod.org \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=paulus@samba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox