All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudio Fontana <cfontana@suse.de>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Eduardo Habkost" <ehabkost@redhat.com>
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Dongjiu Geng" <gengdongjiu@huawei.com>
Subject: Re: [PATCH] target/arm: do not use cc->do_interrupt for KVM directly
Date: Tue, 8 Dec 2020 14:55:26 +0100	[thread overview]
Message-ID: <6b6d65af-5814-27f7-e9c4-937c42e8958c@suse.de> (raw)
In-Reply-To: <b1ef6c6c-1803-a877-b4b7-a12b82288160@suse.de>

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 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?

Ciao,

C

> Ciao,
> 
> Claudio
> 
> 
>>
>>>
>>>> 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
>>>
>>
> 



  reply	other threads:[~2020-12-08 13:57 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 [this message]
2020-12-08 14:34                     ` Philippe Mathieu-Daudé
2020-12-08 16:19                       ` Claudio Fontana
2020-12-08 16:28                       ` Eduardo Habkost
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=6b6d65af-5814-27f7-e9c4-937c42e8958c@suse.de \
    --to=cfontana@suse.de \
    --cc=alex.bennee@linaro.org \
    --cc=ehabkost@redhat.com \
    --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.