Received: from eggs.gnu.org ([208.118.235.92]:47435) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIdgs-0005w7-NO for qemu-devel@nongnu.org; Thu, 21 Mar 2013 07:29:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UIdgo-0000qc-I9 for qemu-devel@nongnu.org; Thu, 21 Mar 2013 07:29:50 -0400 Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: text/plain; charset=us-ascii From: Alexander Graf In-Reply-To: Date: Thu, 21 Mar 2013 12:29:41 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: <2C6016A8-1CF1-423E-AC18-71BEFF2F7444@suse.de> References: <1360823521-32306-1-git-send-email-scottwood@freescale.com> <1360823521-32306-4-git-send-email-scottwood@freescale.com> <6C8C9D12-4ACE-466B-A970-58D7FD78930B@suse.de> <6E1AE030-D8A9-4C0C-97B0-F9BEB21A92CA@suse.de> Subject: Re: [Qemu-devel] [RFC ppc-next PATCH 3/6] memory: add memory_region_to_address() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Scott Wood , "qemu-ppc@nongnu.org list:PowerPC" , qemu-devel qemu-devel On 21.03.2013, at 12:22, Peter Maydell wrote: > On 21 March 2013 11:14, Alexander Graf wrote: >>=20 >> On 21.03.2013, at 12:09, Peter Maydell wrote: >>=20 >>> On 21 March 2013 11:05, Alexander Graf wrote: >>>>=20 >>>> On 21.03.2013, at 12:01, Peter Maydell wrote: >>>>=20 >>>>> On 21 March 2013 10:59, Alexander Graf wrote: >>>>>> On 21.03.2013, at 11:53, Peter Maydell wrote: >>>>>>> Check kvm_arm_register_device() in target-arm/kvm.c. Basically >>>>>>> the VGIC device model calls this function to say "tell the = kernel >>>>>>> where this MemoryRegion is in the system address space, when it >>>>>>> eventually gets mapped". The code in kvm.c uses the memory = system's >>>>>>> Notifier API to get a callback when the region is mapped into >>>>>>> an address space, which it uses to track the offset in the >>>>>>> address space. Finally, we use a machine init notifier so that >>>>>>> just before everything finally starts we can make the KVM ioctls >>>>>>> to say "here is where everything lives". >>>>>>=20 >>>>>> Same thing here. The question is how the kvm-vgic code in QEMU >>>>>> finds out where it got mapped to. Scott adds this patch to do >>>>>> this, but I'd assume you have some other way :) >>>>>=20 >>>>> Hmm? The kvm-vgic code in QEMU doesn't need to know where it >>>>> lives. We have to tell the kernel so it can map its bits of >>>>> registers in at the right place, that's all. >>>>=20 >>>> The kvm-vgic code in QEMU needs to tell the kernel, no? For >>>> that, it needs to know what to tell the kernel. >>>=20 >>> No. As I explained earlier, all the kvm-vgic code needs to do >>> is call kvm_arm_register_device(). That code in kvm.c then takes >>> care of telling the kernel. hw/kvm/arm_gic.c itself never knows or >>> needs to know where it's mapped. This is the whole point of the >>> mechanism involving notifiers. >>=20 >> I fully disagree. Code that talks to the in-kernel device should >> live in hw/kvm/.c, not in some random target-XXX/kvm.c file. >=20 > The code in kvm.c is entirely generic -- it provides a mechanism > for a device to say "this memory region is kernel ID X and it will > want to know where it lives". The kvm.c code will work for any device > with a memory mapped region, whether it's the GIC or something else. >=20 >> Of course the board defines where the device gets mapped to, but >> the communication with the in-kernel device bits should really be >> contained to the device itself. >=20 > You're arguing that every device should implement its own set > of notifier functions so it can get called back when its memory > regions are finally mapped, just so it can make a non-device-specific > KVM ioctl? The obvious thing to do is abstract that functionality > out. What I'm arguing is that every device should look as if it was a QEMU = device. Devices that happen to live in KVM, should still make a = significant effort to expose themselves to the board model as if they = were QEMU devices. So yes, I think the device model should at least register the memory = listener, because only the device model knows what its memory regions = would map to in KVM's world. Not all devices have a single flat region. = Some have more than one. Whether we have a helper function in (generic) kvm.c that can call a = (generic) ioctl to set a device's region X is a different matter. I'd be = open to that if it makes sense. >=20 >> So this is the function that gets invoked on ARM: >>=20 >> static void kvm_arm_machine_init_done(Notifier *notifier, void *data) >> { >> KVMDevice *kd, *tkd; >>=20 >> memory_listener_unregister(&devlistener); >> QSLIST_FOREACH_SAFE(kd, &kvm_devices_head, entries, tkd) { >> if (kd->kda.addr !=3D -1) { >> if (kvm_vm_ioctl(kvm_state, KVM_ARM_SET_DEVICE_ADDR, >> &kd->kda) < 0) { >> fprintf(stderr, "KVM_ARM_SET_DEVICE_ADDRESS failed: = %s\n", >> strerror(errno)); >> abort(); >> } >> } >> g_free(kd); >> } >> } >>=20 >> This only goes one level deep, right? So if you ever have to nest the >> VGIC inside of another MemoryRegion, this will break, right? >=20 > We already nest the VGIC inside another memory region (the a15mpcore > container), and it works fine. This function is just iterating through > "everything any device asked me to tell the kernel about". So kda is the real physical offset? I'm having a hard time reading that = code :). According to this function: static void kvm_arm_devlistener_add(MemoryListener *listener, MemoryRegionSection *section) { KVMDevice *kd; QSLIST_FOREACH(kd, &kvm_devices_head, entries) { if (section->mr =3D=3D kd->mr) { kd->kda.addr =3D section->offset_within_address_space; } } } it's only the offset within its parent region, which would mean it's = broken, no? Alex