On 12/7/20 10:50 PM, Peter Maydell wrote: > On Mon, 7 Dec 2020 at 21:26, Eduardo Habkost <[email protected]> wrote: >> My understanding is that there's no reason for ARM KVM to use >> another approach, and that CPUClass.do_interrupt is not really >> TCG-specific. >> >> Do we have any case where the CPUClass.do_interrupt >> implementation is really TCG-specific, or it is just a >> coincidence that most other accelerators simply don't to call the >> method? It looks like the only cases where the >> CPUClass.do_interrupt assignment is conditional on CONFIG_TCG are >> i386 and s390x. > > Looking at PPC, its kvm_handle_debug() function does a > direct call to ppc_cpu_do_interrupt(). So the code of > its do_interrupt method must be ok-for-KVM, it's just that > it doesn't use the method pointer. (It's doing the same thing > Arm is -- if a debug event turns out not to be for QEMU itself, > inject a suitable exception into the guest.) > > So of our 5 KVM-supporting architectures: > > * i386 and s390x have kernel APIs for "inject suitable > exception", don't need to call do_interrupt, and make > the cc->do_interrupt assignment only ifdef CONFIG_TCG, > so that the code for do_interrupt need not be compiled > into a KVM-only binary. (In both cases the code for the > function is in a source file that the meson.build puts > into the source list only if CONFIG_TCG) > * ppc and arm both need to use this code even in a KVM > only binary. Neither of them #ifdef the cc->do_interrupt > assignment, because there's not much point at the moment > if you're not going to try to compile out the code. > ppc happens to do a direct function call, and arm happens > to go via the cc->do_interrupt pointer, but I don't > think there's much significance in the choice either way. > In both cases, the only places making the call are within > architecture-specific KVM code. > * mips KVM does neither of these things, probably because it is > not sufficiently featureful to have run into the cases > where you might want to re-inject an exception and it's > not being sufficiently used in production for anybody to > have looked at minimising the amount of code in a > KVM-only QEMU binary for it. > > So in conclusion we have a basically 50:50 split between > "use the same do_interrupt code as TCG" and "have a kernel > API to make the kernel do the work", plus one arch that > probably hasn't had to make the choice yet. ¯\_(ツ)_/¯
Why not introduce KVMCpuOperations similar to TCGCpuOperations Claudio is introducing, and declare the do_interrupt(CPUState*) in both structures? Then we can assign the same handler to both fields, TCG keeps calling cc->tcg->do_interrupt(), KVM calls cc->kvm->do_interrupt(). This allow building with a particular accelerator, while staying compliant with the current 50:50 split... > >> Oh, I thought you were arguing that CPUClass.do_interrupt is >> not TCG_specific. > > Well, I don't think it really is TCG-specific. But as > a pragmatic thing, if these two lines in the Arm code > are getting in the way of stopping us from having a > useful compile-time check that code that's not supposed > to call this method isn't calling it, I think the balance > maybe leans towards just making the direct function call. > I guess it depends whether you think people are likely to > accidentally make cc->do_interrupt calls in non-target-specific > code that gets used by KVM (which currently would crash if that > code path is exercised on x86 or s390x, but under the > proposed change would become a compile error). > > thanks > -- PMM >
