From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [PATCH 26/35] kvm: Eliminate KVMState arguments Date: Mon, 10 Jan 2011 21:12:53 +0100 Message-ID: <4D2B6845.7050809@web.de> References: <4D2616D6.4080309@linux.vnet.ibm.com> <4D26D6CF.5070405@web.de> <4D27A16F.9030809@linux.vnet.ibm.com> <4D282489.90506@web.de> <4D2B6506.6070907@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig315442F99F878D41EED6766F" Cc: Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org, Alexander Graf To: Anthony Liguori Return-path: Received: from fmmailgate01.web.de ([217.72.192.221]:59653 "EHLO fmmailgate01.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754081Ab1AJUNA (ORCPT ); Mon, 10 Jan 2011 15:13:00 -0500 In-Reply-To: <4D2B6506.6070907@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig315442F99F878D41EED6766F Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Am 10.01.2011 20:59, Anthony Liguori wrote: > On 01/08/2011 02:47 AM, Jan Kiszka wrote: >> Am 08.01.2011 00:27, Anthony Liguori wrote: >> =20 >>> On 01/07/2011 03:03 AM, Jan Kiszka wrote: >>> =20 >>>> Am 06.01.2011 20:24, Anthony Liguori wrote: >>>> >>>> =20 >>>>> On 01/06/2011 11:56 AM, Marcelo Tosatti wrote: >>>>> >>>>> =20 >>>>>> From: Jan Kiszka >>>>>> >>>>>> QEMU supports only one VM, so there is only one kvm_state per >>>>>> process, >>>>>> and we gain nothing passing a reference to it around. Eliminate an= y >>>>>> need >>>>>> to refer to it outside of kvm-all.c. >>>>>> >>>>>> Signed-off-by: Jan Kiszka >>>>>> CC: Alexander Graf >>>>>> Signed-off-by: Marcelo Tosatti >>>>>> >>>>>> >>>>>> =20 >>>>> I think this is a big mistake. >>>>> >>>>> =20 >>>> Obviously, I don't share your concerns. :) >>>> >>>> >>>> =20 >>>>> Having to manage kvm_state keeps the abstraction lines well defined= =2E >>>>> >>>>> =20 >>>> How does it help? >>>> >>>> >>>> =20 >>>>> Otherwise, it's far too easy for portions of code to call into KVM >>>>> functions that really shouldn't. >>>>> >>>>> =20 >>>> I can't imagine we gain anything from requiring kvm_check_extension >>>> callers to hold a kvm_state "capability". Yes, it's now much easier = to >>>> call kvm_[vm_]ioctl, but that's the key point of this change: >>>> >>>> So far we primarily complicated the internal interface between gener= ic >>>> and arch-dependent kvm parts by requiring kvm_state joggling. But >>>> external users already find interfaces without this restriction >>>> (kvm_log_*, kvm_ioeventfd_*, ...). That's because it's at least >>>> complicated to _cleanly_ pass kvm_state references to all users that= >>>> need it - e.g. sysbus devices like kvmclock or upcoming in-kernel >>>> irqchips. >>>> >>>> =20 >>> I think you're basically making my point for me. >>> >>> ioeventfd is a broken interface. It shouldn't be a VM ioctl but rath= er >>> a VCPU ioctl because PIO events are dispatched on a per-VCPU basis. >>> =20 >> OK, but I don't want to argue about the ioeventfd API. So let's put th= is >> case aside. :) >> >> =20 >>> kvm_state is available as part of CPU state so it's quite easy to get= at >>> if these interfaces just took a CPUState argument (and they should). >>> =20 >> My point is definitely NOT about cpu-bound devices. That case is clear= >> and is not touched at all by this patch. >> >> My point is about devices that have clear system scope like kvmclock, >> ioapic, pit, pic, >=20 > I don't see how ioapic, pit, or pic have a system scope. They are not bound to any CPU like the APIC which you may have in mind. >=20 > I don't know enough about kvmclock. It's just the same. >=20 >> whatever-the-future-will-bring. And about KVM services >> that have global scope like capability checks and other feature >> explorations or VM configurations done by the KVM arch code. You still= >> didn't explain what we gain in these concrete scenarios by handing the= >> technically redundant abstraction kvm_state around, especially _inside= _ >> the KVM core. >> =20 >=20 > If you have to pass around a KVMState pointer, you establish an explici= t > relationship and communication between subsystems. Any place where the= > global KVMState is used is a red flag that something is wrong. It is and will be _only_ used inside kvm-all.c. Again: What is the benefit of restricting access to kvm_check_extension this way? >=20 > I don't see what the advantage to making all of the KVMState global and= > implicit. It seems like a big step backwards to me. Can you give a > very concrete example of where you think it results in easier to > understand code as I don't see how making relationships implicit ever > makes code easier to understand? The best example does not yet exist (fortunately): Just look at patch 28 and then try to pass some kvm_state reference to the kvmclock device. Is this handle worth changing the sysbus API? Jan --------------enig315442F99F878D41EED6766F Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iEYEARECAAYFAk0raEkACgkQitSsb3rl5xSGZgCfVdXw/eTEzovjPnRrAGvkHnsL dIEAmwXCfL0m/OrhB3spRidAbPe4hqzB =6g65 -----END PGP SIGNATURE----- --------------enig315442F99F878D41EED6766F-- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=41097 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PcO72-0005aU-Nr for qemu-devel@nongnu.org; Mon, 10 Jan 2011 15:13:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PcO70-00034R-WB for qemu-devel@nongnu.org; Mon, 10 Jan 2011 15:13:08 -0500 Received: from fmmailgate01.web.de ([217.72.192.221]:59654) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PcO70-00033d-HL for qemu-devel@nongnu.org; Mon, 10 Jan 2011 15:13:06 -0500 Message-ID: <4D2B6845.7050809@web.de> Date: Mon, 10 Jan 2011 21:12:53 +0100 From: Jan Kiszka MIME-Version: 1.0 References: <4D2616D6.4080309@linux.vnet.ibm.com> <4D26D6CF.5070405@web.de> <4D27A16F.9030809@linux.vnet.ibm.com> <4D282489.90506@web.de> <4D2B6506.6070907@linux.vnet.ibm.com> In-Reply-To: <4D2B6506.6070907@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig315442F99F878D41EED6766F" Sender: jan.kiszka@web.de Subject: [Qemu-devel] Re: [PATCH 26/35] kvm: Eliminate KVMState arguments List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org, Alexander Graf This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig315442F99F878D41EED6766F Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Am 10.01.2011 20:59, Anthony Liguori wrote: > On 01/08/2011 02:47 AM, Jan Kiszka wrote: >> Am 08.01.2011 00:27, Anthony Liguori wrote: >> =20 >>> On 01/07/2011 03:03 AM, Jan Kiszka wrote: >>> =20 >>>> Am 06.01.2011 20:24, Anthony Liguori wrote: >>>> >>>> =20 >>>>> On 01/06/2011 11:56 AM, Marcelo Tosatti wrote: >>>>> >>>>> =20 >>>>>> From: Jan Kiszka >>>>>> >>>>>> QEMU supports only one VM, so there is only one kvm_state per >>>>>> process, >>>>>> and we gain nothing passing a reference to it around. Eliminate an= y >>>>>> need >>>>>> to refer to it outside of kvm-all.c. >>>>>> >>>>>> Signed-off-by: Jan Kiszka >>>>>> CC: Alexander Graf >>>>>> Signed-off-by: Marcelo Tosatti >>>>>> >>>>>> >>>>>> =20 >>>>> I think this is a big mistake. >>>>> >>>>> =20 >>>> Obviously, I don't share your concerns. :) >>>> >>>> >>>> =20 >>>>> Having to manage kvm_state keeps the abstraction lines well defined= =2E >>>>> >>>>> =20 >>>> How does it help? >>>> >>>> >>>> =20 >>>>> Otherwise, it's far too easy for portions of code to call into KVM >>>>> functions that really shouldn't. >>>>> >>>>> =20 >>>> I can't imagine we gain anything from requiring kvm_check_extension >>>> callers to hold a kvm_state "capability". Yes, it's now much easier = to >>>> call kvm_[vm_]ioctl, but that's the key point of this change: >>>> >>>> So far we primarily complicated the internal interface between gener= ic >>>> and arch-dependent kvm parts by requiring kvm_state joggling. But >>>> external users already find interfaces without this restriction >>>> (kvm_log_*, kvm_ioeventfd_*, ...). That's because it's at least >>>> complicated to _cleanly_ pass kvm_state references to all users that= >>>> need it - e.g. sysbus devices like kvmclock or upcoming in-kernel >>>> irqchips. >>>> >>>> =20 >>> I think you're basically making my point for me. >>> >>> ioeventfd is a broken interface. It shouldn't be a VM ioctl but rath= er >>> a VCPU ioctl because PIO events are dispatched on a per-VCPU basis. >>> =20 >> OK, but I don't want to argue about the ioeventfd API. So let's put th= is >> case aside. :) >> >> =20 >>> kvm_state is available as part of CPU state so it's quite easy to get= at >>> if these interfaces just took a CPUState argument (and they should). >>> =20 >> My point is definitely NOT about cpu-bound devices. That case is clear= >> and is not touched at all by this patch. >> >> My point is about devices that have clear system scope like kvmclock, >> ioapic, pit, pic, >=20 > I don't see how ioapic, pit, or pic have a system scope. They are not bound to any CPU like the APIC which you may have in mind. >=20 > I don't know enough about kvmclock. It's just the same. >=20 >> whatever-the-future-will-bring. And about KVM services >> that have global scope like capability checks and other feature >> explorations or VM configurations done by the KVM arch code. You still= >> didn't explain what we gain in these concrete scenarios by handing the= >> technically redundant abstraction kvm_state around, especially _inside= _ >> the KVM core. >> =20 >=20 > If you have to pass around a KVMState pointer, you establish an explici= t > relationship and communication between subsystems. Any place where the= > global KVMState is used is a red flag that something is wrong. It is and will be _only_ used inside kvm-all.c. Again: What is the benefit of restricting access to kvm_check_extension this way? >=20 > I don't see what the advantage to making all of the KVMState global and= > implicit. It seems like a big step backwards to me. Can you give a > very concrete example of where you think it results in easier to > understand code as I don't see how making relationships implicit ever > makes code easier to understand? The best example does not yet exist (fortunately): Just look at patch 28 and then try to pass some kvm_state reference to the kvmclock device. Is this handle worth changing the sysbus API? Jan --------------enig315442F99F878D41EED6766F Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iEYEARECAAYFAk0raEkACgkQitSsb3rl5xSGZgCfVdXw/eTEzovjPnRrAGvkHnsL dIEAmwXCfL0m/OrhB3spRidAbPe4hqzB =6g65 -----END PGP SIGNATURE----- --------------enig315442F99F878D41EED6766F--