From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DC06C10F0E for ; Fri, 12 Apr 2019 06:34:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E4FF420643 for ; Fri, 12 Apr 2019 06:34:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.b="XzRIG9EA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726914AbfDLGeQ (ORCPT ); Fri, 12 Apr 2019 02:34:16 -0400 Received: from ozlabs.org ([203.11.71.1]:59127 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726728AbfDLGeQ (ORCPT ); Fri, 12 Apr 2019 02:34:16 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 44gSm51wyvz9sB8; Fri, 12 Apr 2019 16:34:12 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1555050853; bh=GE2ACxqOm4d7h01GE3sIM5fpW18t9RzlGTu47IkB22Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XzRIG9EAVFCzz0uf8DO3oRTBJyNQNI0HLHWx4WYIIXJpkGB4NPG1yyWy7ygdOZ6c6 7faYbyw2Z2ILJcdS8c8Vq5jIl5mENT7C1SihevOOfloPr2ozicwy2/wO4iYwepeDPM JDpcT6EHTGRZvqMNCUc3vQwkhbrOpBN6GZvaZI6E= Date: Fri, 12 Apr 2019 16:32:24 +1000 From: David Gibson To: =?iso-8859-1?Q?C=E9dric?= Le Goater Cc: kvm-ppc@vger.kernel.org, Paul Mackerras , kvm@vger.kernel.org, Paolo Bonzini Subject: Re: [PATCH 1/2] KVM: introduce a 'release' method for KVM devices Message-ID: <20190412063224.GG8005@umbus.fritz.box> References: <20190411135302.27509-1-clg@kaod.org> <20190411135302.27509-2-clg@kaod.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="qoTlaiD+Y2fIM3Ll" Content-Disposition: inline In-Reply-To: <20190411135302.27509-2-clg@kaod.org> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org --qoTlaiD+Y2fIM3Ll Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Apr 11, 2019 at 03:53:01PM +0200, C=E9dric 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. >=20 > 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. >=20 > Once 'release' is called, the 'destroy' method will not be called > anymore as the device is removed from the device list of the VM. >=20 > Cc: Paolo Bonzini > Signed-off-by: C=E9dric Le Goater Reviewed-by: David Gibson 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(+) >=20 > 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); > =20 > + /* > + * 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 =3D filp->private_data; > struct kvm *kvm =3D dev->kvm; > =20 > + if (!dev) > + return -ENODEV; > + > + if (dev->kvm !=3D 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; > } --=20 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 --qoTlaiD+Y2fIM3Ll Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAlywMPYACgkQbDjKyiDZ s5JNdw//fl/WNN5yhRtn4wkOxG7FX9a38F5YRDxFLw3/0wk1Yi91mnjav1OZmRPk k6FaRAwvud25oJLZCC23TUVGgbC5IdOI/Ftr3HYUlnR6a0f13Ezxjp3cE1WI6s2c ZEOiTkaqWnwXKSY2Dxh5iBvVLk33FWX4RxTuZH+/EI1VQr4BljByygVCBRzt3PRU 8/stqUO0USNwm2hGHJbty4XSx3i5o43lIKH2HfrBCW28wKWjJ+erLtdQHfpysraN f8LhoTwfc6mNbDz4P1jwUf8APqiZV4LkoFKhSG96nq7LCRmv77srAoylBIqjJ6oy ymu2txF1KFtl0xNHOrfn4F4h+0G1VFaUJxgjORTougpXczBHUJbgaZ2FFDsLagYn BT9rQnAUgQPcWGR6+hG1f+tvD02LexMeIxMl+2N0k8IHOE/0myx7G7p/bvFVo/d4 roqyDNdIBEvb5NwJqjrotIUWH1w6rGLuyzaIDl338CoUDdvWWGB+c8+pkkL9gQn0 X/pJSt8rSfW3Qz+DQiI2L6qigNVnvDcIUWOl8vIUZSsIca895zTsAj4MJVqsziT4 mifgGmxNciLIAW/hHKdbxeaTPJynw6GfEbsKGwWOTOcG6Rv4W35HmFkFodGM6DtP r1wk97ze2YcwlQyS19qBCFNgJqaVM6EflCkgx+zr9QmXgqYt0IM= =Xp/i -----END PGP SIGNATURE----- --qoTlaiD+Y2fIM3Ll--