Received: from eggs.gnu.org ([2001:4830:134:3::10]:35850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9hyQ-0001Id-M8 for qemu-devel@nongnu.org; Wed, 14 Aug 2013 16:47:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V9hyK-0008SL-Jp for qemu-devel@nongnu.org; Wed, 14 Aug 2013 16:47:18 -0400 Received: from cantor2.suse.de ([195.135.220.15]:58261 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9hyK-0008SB-7N for qemu-devel@nongnu.org; Wed, 14 Aug 2013 16:47:12 -0400 Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: text/plain; charset=us-ascii From: Alexander Graf In-Reply-To: <20130814203359.GA8141@cbox> Date: Wed, 14 Aug 2013 22:47:08 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <859532B4-36D7-450B-9AF2-2245FF669880@suse.de> References: <8B645B6D-9427-4784-95E1-6B0D17932F06@suse.de> <20130814172604.GC11390@cbox> <04BA3443-74C6-47B9-AABD-30DC200A95A8@suse.de> <20130814173949.GF11390@cbox> <364D0AE6-E3D4-45DE-A484-A37C26726C2D@suse.de> <20130814181817.GH11390@cbox> <09E07C3D-914F-4EF9-BFAE-673B260DF921@suse.de> <20130814182803.GI11390@cbox> <20130814203359.GA8141@cbox> Subject: Re: [Qemu-devel] [RFC 0/2] target-arm: Provide '-cpu host' when running KVM List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Christoffer Dall Cc: Peter Maydell , patches@linaro.org, qemu-devel@nongnu.org, =?iso-8859-1?Q?Andreas_F=E4rber?= , kvmarm@lists.cs.columbia.edu On 14.08.2013, at 22:33, Christoffer Dall wrote: > On Wed, Aug 14, 2013 at 09:28:10PM +0200, Alexander Graf wrote: >>=20 >> On 14.08.2013, at 20:28, Christoffer Dall wrote: >>=20 >>> On Wed, Aug 14, 2013 at 08:21:54PM +0200, Alexander Graf wrote: >>>>=20 >>>> On 14.08.2013, at 20:18, Christoffer Dall wrote: >>>>=20 >>>>> On Wed, Aug 14, 2013 at 07:44:25PM +0200, Alexander Graf wrote: >>>>>>=20 >>>>>> On 14.08.2013, at 19:39, Christoffer Dall wrote: >>>>>>=20 >>>>>>> On Wed, Aug 14, 2013 at 07:31:59PM +0200, Alexander Graf wrote: >>>>>>>>=20 >>>>>>>> On 14.08.2013, at 19:26, Christoffer Dall wrote: >>>>>>>>=20 >>>>>>>>> On Wed, Aug 14, 2013 at 11:30:46AM +0200, Alexander Graf = wrote: >>>>>>>>>>=20 >>>>>>>>>> On 14.08.2013, at 11:23, Peter Maydell wrote: >>>>>>>>>>=20 >>>>>>>>>>> On 14 August 2013 10:11, Alexander Graf = wrote: >>>>>>>>>>>> You're right, the main difference is that KVM doesn't have = any >>>>>>>>>>>> idea what a "host" style CPU is. It only knows how to = report to QEMU >>>>>>>>>>>> what the current host CPU would be, so that anything from = VCPU_INIT >>>>>>>>>>>> onwards is 100% identical regardless of whether the user = said >>>>>>>>>>>> -cpu host or -cpu xxx. >>>>>>>>>>>>=20 >>>>>>>>>>>> I'm still puzzled on how this will work with BIG.little = btw. >>>>>>>>>>>=20 >>>>>>>>>>> The rough idea is that for BIG.little the kernel must trap = the >>>>>>>>>>> ID registers at least (so that the vcpu seems consistent to = the >>>>>>>>>>> guest whether it's running on the big or the little core). = For >>>>>>>>>>> "-cpu host" the guest would see whatever is the most = low-overhead >>>>>>>>>>> for the kernel to provide (ie assuming the big and little = CPUs >>>>>>>>>>> are roughly-similar you could make -cpu host provide = something >>>>>>>>>>> that looks to the guest like the big CPU and don't have to = trap >>>>>>>>>>> quite as much as you would for providing a vcpu that wasn't = the >>>>>>>>>>> same as either the big or little one). >>>>>>>>>>=20 >>>>>>>>>> So -cpu host in this case wouldn't actually expose the host = CPU 1:1, but instead a cortex-a15 even when it's run on an a7 BIG.little = core. I see. >>>>>>>>>>=20 >>>>>>>>> Yes, from the discussion we've had the whole picture just = becomes to >>>>>>>>> blurry when you start presenting multiple different CPUs to = the guest >>>>>>>>> and there's really no need to that I'm aware of. >>>>>>>>>=20 >>>>>>>>> In fact the -cpu host case fits quite nicely with this state = of mind; >>>>>>>>> the kernel is free to decide based on the specific hardware = and config >>>>>>>>> on which it's running how to handle VMs on BL. >>>>>>>>=20 >>>>>>>> So why not have a vm ioctl to fetch the "best match" vcpu type? = I don't like the idea of adding any awareness of a "host" type to the = normal vcpu creation process. >>>>>>>>=20 >>>>>>>>=20 >>>>>>> That's actually what I suggested initially. I'm not really a = QEMU >>>>>>> expert, but I think Peter already answered this question: he = doesn't >>>>>>> want to support hundreds of CPU models in QEMU just to be able = to run >>>>>>> KVM when it's not necessary. >>>>>>>=20 >>>>>>> If his argument holds in that you can support -cpu host without = having a >>>>>>> model for that specific cpu in QEMU, then indeed it is a strong >>>>>>> argument, and we have the problem with ARMv8 already, and this = goes a >>>>>>> long way to solve that. No? >>>>>>=20 >>>>>> That's up for QEMU to decide. With the "fetch and push" model we = can support both flavors from user space. It also makes the kernel side = more reproducible and obvious. There's simply no way to add hacks like = "If I'm a -cpu host type do xxx" in KVM, because KVM never knows that it = is running -cpu host. >>>>>>=20 >>>>> Do we have historical examples of this knowledge being abused = inside the >>>>> kernel for other archs? If not, can we come up with a technical >>>>> scenario where it may happen on ARM? >>>>=20 >>>> if (cpu =3D=3D host_cpu) { >>>> vgic_version =3D get_host_vgic_version(); >>>> } >>>>=20 >>>> would be an example :).=20 >>>=20 >>> Not really, this is driven from user space, but ok. >>>=20 >>>> Everything -cpu host does has to be reproducible without -cpu host, = otherwise our compatibility layering is broken. So why not model the API = like it from the beginning? >>>>=20 >>>>>=20 >>>>> Also, not really sure if such code should be controlled through = the user >>>>> space API; ideally we would catch bad coding behavior in the = kernel >>>>> during code review. >>>>>=20 >>>>> The only reason I originally suggested the "fetch and push" model = was >>>>> that I thought user space would need to know the specific CPU = model for >>>>> things to work and possibly for things like debugging and = migration, but >>>>> since I have been almost convinced otherwise, I don't see any real >>>>> technical arguments for not adding -cpu host support in the kernel = side. >>>>>=20 >>>>> Note that this doesn't prevent us from adding an IOCTL later that = gives >>>>> you the host CPU type in KVM terminology if we find it useful. = But, I >>>>> think the reduced headache with ARMv8 right now is a good argument = to >>>>> proceed with Peter's RFC and kernel support for same. >>>>=20 >>>> There's really almost no difference from the QEMU point of view if = Peter choses to implement it the way he does today. He can ask the = kernel for the vcpu target and pass that exact number back into the = kernel. >>>>=20 >>>>=20 >>> =46rom the kernel point of view though we have to make some informed >>> decision about which "best CPU target" value to return on any given = new >>> core >>=20 >> We have to make that decision internally anyways, because we have to = choose some CPU target for the host one. >>=20 >=20 > Are we sure that will always be the case? That's how it's structured > now, yes, but maybe we can do something more intelligent (which is = what > I meant with "generic handling" below). It's a bit fuzzy for me to > think about right now, but I just want to make sure we don't shoot > ourselves in the foot with the choice of ABI. Exactly that cleverness is what I'd prefer to avoid, as it breaks = reproducibility with cross-chip environments. >=20 >>> , where TARGET_HOST may simply work through generic handling of id >>> registers, traps etc. and provide better performance than say, "I = don't >>> really know this host CPU, so I'm just going to tell you A15 and = trap >>> everything"... >>=20 >> Yes. >>=20 >> target_vcpu_id =3D kvm_vm_ioctl(KVM_VM_GET_BEST_CPU_TARGET); >>=20 >> /* Old kernels only support A15 hosts */ >> if (target_vcpu_id < 0) >> target_vcpu_id =3D VCPU_CORTEX_A15; >>=20 >> kvm_vcpu_ioctl(vcpu_fd, KVM_INIT_VCPU, target_vcpu_id); >>=20 >=20 > I get this part, but imagine the kernel not knowing the target_cpu id, > but just passing through whatever the hardware gives you to the guest. Don't you have to handle core specific registers anyway? > I'm not saying that's necessarily going to happen or that it would be = a > great thing, but do we want to prevent this from ever happening = through > our choice of ABI? I think so, yes. Can you run Linux on a core that hasn't been enabled? = Why should you be able to run KVM on a core that hasn't been enabled? = I'm not talking about QEMU here - that one should be happy to be = ignorant. But the kernel side needs to know about the core either way, = no? Alex