All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudio Fontana <cfontana@suse.de>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: "Paul Durrant" <paul@xen.org>, "Jason Wang" <jasowang@redhat.com>,
	qemu-devel@nongnu.org, "Peter Xu" <peterx@redhat.com>,
	haxm-team@intel.com, "Colin Xu" <colin.xu@intel.com>,
	gengdongjiu@huawei.com, "Olaf Hering" <ohering@suse.de>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Bruce Rogers" <brogers@suse.com>,
	"Emilio G . Cota" <cota@braap.org>,
	"Anthony Perard" <anthony.perard@citrix.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Cameron Esfahani" <dirty@apple.com>,
	"Dario Faggioli" <dfaggioli@suse.com>,
	"Roman Bolshakov" <r.bolshakov@yadro.com>,
	"Sunil Muthuswamy" <sunilmut@microsoft.com>,
	"Alex Bennee" <alex.bennee@linaro.org>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	"Wenchao Wang" <wenchao.wang@intel.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [RFC v6 07/11] i386: move TCG cpu class initialization out of helper.c
Date: Fri, 27 Nov 2020 20:47:00 +0100	[thread overview]
Message-ID: <c1d20b34-be23-bb42-9fc6-5395a390c037@suse.de> (raw)
In-Reply-To: <20201127190424.GH2271382@habkost.net>

Hi Eduardo,

On 11/27/20 8:04 PM, Eduardo Habkost wrote:
> Now that I understand what you are doing here, I have specific
> questions about the functions you are moving, below:
> 
> On Thu, Nov 26, 2020 at 11:32:14PM +0100, Claudio Fontana wrote:
>> Signed-off-by: Claudio Fontana <cfontana@suse.de>
> [...]
>> @@ -1495,7 +1497,8 @@ static inline uint64_t x86_cpu_xsave_components(X86CPU *cpu)
>>             cpu->env.features[FEAT_XSAVE_COMP_LO];
>>  }
>>  
>> -const char *get_register_name_32(unsigned int reg)
>> +/* Return name of 32-bit register, from a R_* constant */
>> +static const char *get_register_name_32(unsigned int reg)
>>  {
>>      if (reg >= CPU_NB_REGS32) {
>>          return NULL;
>> @@ -7012,13 +7015,6 @@ static void x86_cpu_set_pc(CPUState *cs, vaddr value)
>>      cpu->env.eip = value;
>>  }
>>  
>> -static void x86_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
>> -{
>> -    X86CPU *cpu = X86_CPU(cs);
>> -
>> -    cpu->env.eip = tb->pc - tb->cs_base;
>> -}
> 
> Question to be answered in the commit message: how can somebody
> be sure this code is not necessary for any other accelerators?
> The TranslationBlock* argument is a hint, but not a guarantee.


easiest is to just trace the calls, but there is a also helpful description of all these methods in hw/core/cpu.h.

$ mkid --include="C"
$ gid synchronize_from_tb

include/hw/core/cpu.h:110: *       also implement the synchronize_from_tb hook.
include/hw/core/cpu.h:111: * @synchronize_from_tb: Callback for synchronizing state from a TCG
include/hw/core/cpu.h:194:    void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb);
accel/tcg/cpu-exec.c:195:        if (cc->synchronize_from_tb) {
accel/tcg/cpu-exec.c:196:            cc->synchronize_from_tb(cpu, last_tb);
target/arm/cpu.c:2245:    cc->synchronize_from_tb = arm_cpu_synchronize_from_tb;
target/avr/cpu.c:210:    cc->synchronize_from_tb = avr_cpu_synchronize_from_tb;
target/hppa/cpu.c:146:    cc->synchronize_from_tb = hppa_cpu_synchronize_from_tb;
target/microblaze/cpu.c:325:    cc->synchronize_from_tb = mb_cpu_synchronize_from_tb;
target/mips/cpu.c:241:    cc->synchronize_from_tb = mips_cpu_synchronize_from_tb;
target/riscv/cpu.c:546:    cc->synchronize_from_tb = riscv_cpu_synchronize_from_tb;
target/rx/cpu.c:192:    cc->synchronize_from_tb = rx_cpu_synchronize_from_tb;
target/sh4/cpu.c:225:    cc->synchronize_from_tb = superh_cpu_synchronize_from_tb;
target/sparc/cpu.c:871:    cc->synchronize_from_tb = sparc_cpu_synchronize_from_tb;
target/tricore/cpu.c:165:    cc->synchronize_from_tb = tricore_cpu_synchronize_from_tb;
target/i386/tcg/cpu.c:129:    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;

> Maybe we should rename CPUClass.synchronize_from_tb to
> CPUClass.tcg_synchronize_from_tb?  Maybe we should have a

possibly, yes.

> separate TCGCpuOperations struct to carry TCG-specific methods?


interesting, will think about it.

> 
> (The same questions above apply to the other methods below)
> 
> 
>> -
>>  int x86_cpu_pending_interrupt(CPUState *cs, int interrupt_request)
>>  {
>>      X86CPU *cpu = X86_CPU(cs);
>> @@ -7252,17 +7248,18 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
>>      cc->class_by_name = x86_cpu_class_by_name;
>>      cc->parse_features = x86_cpu_parse_featurestr;
>>      cc->has_work = x86_cpu_has_work;
>> +
>>  #ifdef CONFIG_TCG
>> -    cc->do_interrupt = x86_cpu_do_interrupt;
>> -    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
> 
> These two are in seg_helper.c, so I agree it makes sense to keep
> it in tcg_cpu_common_class_init().
> 
> I'd like to understand why they are TCG-specific, though.  Are
> CPUClass.do_interrupt and CPUClass.cpu_exec_enter TCG-specific on
> all architectures, or only in x86?

cpu_exec_enter: yes, tcg only on all archs.

Traces as above, it is only called by

accel/tcg/cpu-exec.c

cc->do_interrupt() is very interesting, it _should_ be the same story,
the use of cc->do_interrupt() is normally relegated to accel/tcg/cpu-exec.c,
or to the various implementations of cpu_exec_interrupt (also tcg-specific).

_BUT_ there is an exception in arm64 where it seems to be (strangely) used for kvm64:

So in this case the arm kvm64 code is the outlier. There are two calls, one introduced in 2015 and one in 2020:

commit e24fd076a59604c4ba3c05fe9d19ea6fc5320a12
Author: Dongjiu Geng <gengdongjiu@huawei.com>
Date:   Tue May 12 11:06:08 2020 +0800

    target-arm: kvm64: handle SIGBUS signal from kernel or KVM


commit 34c45d53026d9c135415d034a8bc30c1a30acf1c
Author: Alex Bennée <alex.bennee@linaro.org>
Date:   Thu Dec 17 13:37:15 2015 +0000

    target-arm: kvm - re-inject guest debug exceptions


Maybe Alex and Dongjiu Geng (or maybe Peter?) can shed some light on whether this is intentional, or an oversight?

It is the one and only use of cc->do_interrupt outside of TCG. So strange.


> 
>> -#endif
>> +    tcg_cpu_common_class_init(cc);
>> +#endif /* CONFIG_TCG */
>> +
>>      cc->dump_state = x86_cpu_dump_state;
>>      cc->set_pc = x86_cpu_set_pc;
>> -    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
>>      cc->gdb_read_register = x86_cpu_gdb_read_register;
>>      cc->gdb_write_register = x86_cpu_gdb_write_register;
>>      cc->get_arch_id = x86_cpu_get_arch_id;
>>      cc->get_paging_enabled = x86_cpu_get_paging_enabled;
>> +
>>  #ifndef CONFIG_USER_ONLY
>>      cc->asidx_from_attrs = x86_asidx_from_attrs;
>>      cc->get_memory_mapping = x86_cpu_get_memory_mapping;
>> @@ -7273,7 +7270,8 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
>>      cc->write_elf32_note = x86_cpu_write_elf32_note;
>>      cc->write_elf32_qemunote = x86_cpu_write_elf32_qemunote;
>>      cc->vmsd = &vmstate_x86_cpu;
>> -#endif
>> +#endif /* !CONFIG_USER_ONLY */
>> +
>>      cc->gdb_arch_name = x86_gdb_arch_name;
>>  #ifdef TARGET_X86_64
>>      cc->gdb_core_xml_file = "i386-64bit.xml";
>> @@ -7281,15 +7279,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
>>  #else
>>      cc->gdb_core_xml_file = "i386-32bit.xml";
>>      cc->gdb_num_core_regs = 50;
>> -#endif
>> -#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
>> -    cc->debug_excp_handler = breakpoint_handler;
> 
> That's in bpt_helper.c, also TCG-specific.  Makes sense to move
> it to tcg_cpu_common_class_init().
> 
> Is CPUClass.debug_excp_handler() TCG-specific in all
> architectures, or only in x86?
> 
>> -#endif
>> -    cc->cpu_exec_enter = x86_cpu_exec_enter;
>> -    cc->cpu_exec_exit = x86_cpu_exec_exit;
> 
> I have a question about those two functions below[1].
> 
>> -#ifdef CONFIG_TCG
>> -    cc->tcg_initialize = tcg_x86_init;
> 
> The name makes this is obviously TCG-specific, so it makes sense
> to move it to tcg_cpu_common_class_init().
> 
>> -    cc->tlb_fill = x86_cpu_tlb_fill;
> 
> This is in excp_helper.c (TCG-specific), so it makes sense to
> move it to tcg_cpu_common_class_init().
> 
> Is CPUClass.tlb_fill TCG-specific in all architectures, or only
> in x86?


TCG-specific on all, real CPU has its own real TLB.

Only accel/tcg/ uses the code.

> 
>>  #endif
>>      cc->disas_set_info = x86_disas_set_info;
>>  
> [...]
>> -/* Frob eflags into and out of the CPU temporary format.  */
>> -
>> -void x86_cpu_exec_enter(CPUState *cs)
>> -{
>> -    X86CPU *cpu = X86_CPU(cs);
>> -    CPUX86State *env = &cpu->env;
>> -
>> -    CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
>> -    env->df = 1 - (2 * ((env->eflags >> 10) & 1));
>> -    CC_OP = CC_OP_EFLAGS;
>> -    env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
>> -}
>> -
>> -void x86_cpu_exec_exit(CPUState *cs)
>> -{
>> -    X86CPU *cpu = X86_CPU(cs);
>> -    CPUX86State *env = &cpu->env;
>> -
>> -    env->eflags = cpu_compute_eflags(env);
>> -}
> 
> [1]
> 
> How exactly can we be 100% sure this is not used by other
> accelerators?


The only calls to these methods are from accel/tcg/cpu-exec.c .



> 
>> -
>>  #ifndef CONFIG_USER_ONLY
>>  uint8_t x86_ldub_phys(CPUState *cs, hwaddr addr)
>>  {
> [...]
> 

I think that this exercise has been useful, and btw I am really interested about the possible comments from Alex or Geng DongJiu
on the extraordinary use of cc->do_interrupt for kvm64 on AArch64,

Thanks,

Ciao,

Claudio


  reply	other threads:[~2020-11-27 19:48 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-26 22:32 [RFC v6 00/11] i386 cleanup Claudio Fontana
2020-11-26 22:32 ` [RFC v6 01/11] i386: move kvm accel files into kvm/ Claudio Fontana
2020-11-26 22:32 ` [RFC v6 02/11] i386: move whpx accel files into whpx/ Claudio Fontana
2020-11-26 22:32 ` [RFC v6 03/11] i386: move hax accel files into hax/ Claudio Fontana
2020-11-26 22:32 ` [RFC v6 04/11] i386: hvf: remove stale MAINTAINERS entry for old hvf stubs Claudio Fontana
2020-11-26 22:32 ` [RFC v6 05/11] i386: move TCG accel files into tcg/ Claudio Fontana
2020-11-26 22:32 ` [RFC v6 06/11] i386: move cpu dump out of helper.c into cpu-dump.c Claudio Fontana
2020-11-26 22:32 ` [RFC v6 07/11] i386: move TCG cpu class initialization out of helper.c Claudio Fontana
2020-11-27 19:04   ` Eduardo Habkost
2020-11-27 19:47     ` Claudio Fontana [this message]
2020-11-27 20:43       ` Eduardo Habkost
2020-11-29 11:53         ` Claudio Fontana
2020-11-26 22:32 ` [RFC v6 08/11] accel: extend AccelState and AccelClass to user-mode Claudio Fontana
2021-01-11 18:43   ` Claudio Fontana
2021-01-12  9:23     ` Claudio Fontana
2020-11-26 22:32 ` [RFC v6 09/11] accel: replace struct CpusAccel with AccelOpsClass Claudio Fontana
2020-11-26 22:32 ` [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass Claudio Fontana
2020-11-27  6:21   ` Paolo Bonzini
2020-11-27  8:59     ` Claudio Fontana
2020-11-27 11:22       ` Claudio Fontana
2020-11-27 11:41         ` Claudio Fontana
2020-11-27 13:31           ` Paolo Bonzini
2020-11-27 13:32             ` Claudio Fontana
2020-12-18 17:51     ` Claudio Fontana
2020-12-18 18:01       ` Paolo Bonzini
2020-12-18 18:04         ` Claudio Fontana
2020-12-18 21:55           ` Claudio Fontana
2020-12-18 22:30             ` Claudio Fontana
2020-12-18 23:00               ` Claudio Fontana
2021-01-11 16:13                 ` Claudio Fontana
2021-01-11 18:08                   ` Claudio Fontana
2021-01-11 22:35                   ` Eduardo Habkost
2021-01-11 23:35                     ` Claudio Fontana
2020-11-27 17:06   ` Eduardo Habkost
2020-11-27 17:58     ` Claudio Fontana
2020-11-27 18:13       ` Eduardo Habkost
2020-11-27 18:20         ` Claudio Fontana
2020-11-26 22:32 ` [RFC v6 11/11] i386: split cpu accelerators from cpu.c, using AccelCPUClass Claudio Fontana
2020-11-27 17:41   ` Eduardo Habkost
2020-11-27 17:53     ` Claudio Fontana
2020-11-27 18:09       ` Eduardo Habkost
2020-11-27 18:16         ` Claudio Fontana
2020-11-27 18:33           ` Eduardo Habkost

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=c1d20b34-be23-bb42-9fc6-5395a390c037@suse.de \
    --to=cfontana@suse.de \
    --cc=alex.bennee@linaro.org \
    --cc=anthony.perard@citrix.com \
    --cc=brogers@suse.com \
    --cc=colin.xu@intel.com \
    --cc=cota@braap.org \
    --cc=dfaggioli@suse.com \
    --cc=dirty@apple.com \
    --cc=ehabkost@redhat.com \
    --cc=gengdongjiu@huawei.com \
    --cc=haxm-team@intel.com \
    --cc=jasowang@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=ohering@suse.de \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=r.bolshakov@yadro.com \
    --cc=richard.henderson@linaro.org \
    --cc=sstabellini@kernel.org \
    --cc=sunilmut@microsoft.com \
    --cc=thuth@redhat.com \
    --cc=wenchao.wang@intel.com \
    /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.