All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Dongjiu Geng" <gengdongjiu@huawei.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Claudio Fontana" <cfontana@suse.de>,
	"QEMU Developers" <qemu-devel@nongnu.org>
Subject: Re: [PATCH] target/arm: do not use cc->do_interrupt for KVM directly
Date: Tue, 8 Dec 2020 11:28:21 -0500	[thread overview]
Message-ID: <20201208162821.GK1289986@habkost.net> (raw)
In-Reply-To: <b63dbed8-5e37-4b1c-2e5b-86fbd8bd47ba@redhat.com>

On Tue, Dec 08, 2020 at 03:34:03PM +0100, Philippe Mathieu-Daudé wrote:
> On 12/8/20 2:55 PM, Claudio Fontana wrote:
> > On 12/8/20 2:51 PM, Claudio Fontana wrote:
> >> On 12/8/20 2:27 PM, Philippe Mathieu-Daudé wrote:
> >>> On 12/7/20 10:50 PM, Peter Maydell wrote:
> >>>> On Mon, 7 Dec 2020 at 21:26, Eduardo Habkost <ehabkost@redhat.com> 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...
> >>
> >>
> >> Hi Philippe,
> >>
> >> in principle interesting, but KVMCpuOperations would end up currently containing do_interrupt only..
> >> seems a bit overkill for just one method.
> 
> I don't see this being a problem, if this makes code clearer
> (think about maintainability).
> 
> > I mean, all the others in CPUClass are common between TCG and KVM, I don't see a lot that is KVM-only there that would warrant a KVMCPUOps structure
> > 
> >> Or where you thinking of ways to refactor current kvm code to use methods in CPUClass similarly to what Tcg does?
> >>
> > 
> > But maybe this is where you were going with this?
> 
> No, not really. I'm looking for a design to enforce correctness,
> while keeping the 2 choices Peter mentioned available.
> 
> - "use the same do_interrupt code as TCG":
> 
> cc->tcg.do_interrupt = x86_cpu_do_interrupt;
> cc->kvm.do_interrupt = NULL;
> 
> cc->tcg.do_interrupt = s390_cpu_do_interrupt;
> cc->kvm.do_interrupt = NULL;
> 
> - "have a kernel API to make the kernel do the work"
> 
> cc->tcg.do_interrupt = arm_cpu_do_interrupt;
> cc->kvm.do_interrupt = arm_cpu_do_interrupt;
> 
> cc->tcg.do_interrupt = ppc_cpu_do_interrupt;
> cc->kvm.do_interrupt = ppc_cpu_do_interrupt;
> 
> Looks easy to review, hard to misplace #ifdef'ry.

So, methods that have accel-specific implementations, which is
exactly why we have the CpusAccel struct (renamed to
AccelCpuClass in Claudio's cleanup series).

Is there any reason to not move CPUClass.do_interrupt to
AccelCpuClass.do_interrupt?

-- 
Eduardo



  parent reply	other threads:[~2020-12-08 16:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-07  8:40 [PATCH] target/arm: do not use cc->do_interrupt for KVM directly Claudio Fontana
2020-12-07 13:09 ` Philippe Mathieu-Daudé
2020-12-07 13:59 ` Alex Bennée
2020-12-07 17:49 ` Eduardo Habkost
2020-12-07 18:07   ` Peter Maydell
2020-12-07 18:18     ` Claudio Fontana
2020-12-07 18:28     ` Eduardo Habkost
2020-12-07 20:56       ` Peter Maydell
2020-12-07 21:01         ` Peter Maydell
2020-12-07 21:06         ` Claudio Fontana
2020-12-07 21:12           ` Peter Maydell
2020-12-07 21:17             ` Claudio Fontana
2020-12-07 21:28             ` Eduardo Habkost
2020-12-07 21:26           ` Eduardo Habkost
2020-12-07 21:50             ` Peter Maydell
2020-12-08 13:27               ` Philippe Mathieu-Daudé
2020-12-08 13:51                 ` Claudio Fontana
2020-12-08 13:55                   ` Claudio Fontana
2020-12-08 14:34                     ` Philippe Mathieu-Daudé
2020-12-08 16:19                       ` Claudio Fontana
2020-12-08 16:28                       ` Eduardo Habkost [this message]
2020-12-08 17:43                         ` Claudio Fontana
2020-12-07 18:08   ` Claudio Fontana
2020-12-07 18:14     ` Peter Maydell
2020-12-07 18:17       ` Claudio Fontana

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201208162821.GK1289986@habkost.net \
    --to=ehabkost@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=cfontana@suse.de \
    --cc=gengdongjiu@huawei.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.