mbox series

[RFC,00/19] accel: Introduce AccelvCPUState opaque structure

Message ID 20210303182219.1631042-1-philmd@redhat.com (mailing list archive)
Headers show
Series accel: Introduce AccelvCPUState opaque structure | expand

Message

Philippe Mathieu-Daudé March 3, 2021, 6:22 p.m. UTC
Hi,

This series introduces the 'AccelvCPUState' which is forward
declared opaque in "cpu.h", then each accelerator define it.

The opaque CPUState::accel_vcpu pointer is shared by all
accelerators (not a problem because there can be at most
one accelerator per vCPU).

Series is organized as:
- preliminary trivial cleanups
- introduce AccelvCPUState
- move WHPX fields (build-tested)
- move HAX fields (not tested)
- move KVM fields (build-tested)
- move HVF fields (not tested)

For now vcpu_dirty is still shared in CPUState.

Sending as RFC to see if it is worthwhile.

Regards,

Phil.

Philippe Mathieu-Daudé (19):
  target/i386/hvf: Use boolean value for vcpu_dirty
  target/s390x/kvm: Simplify debug code
  target/s390x/kvm: Reduce deref by declaring 'struct kvm_run' on stack
  cpu: Croup accelerator-specific fields altogether
  cpu: Introduce AccelvCPUState opaque structure
  accel/whpx: Add typedef for 'struct whpx_vcpu'
  accel/whpx: Rename struct whpx_vcpu -> AccelvCPUState
  accel/whpx: Use 'accel_vcpu' generic pointer
  accel/hax: Add typedef for 'struct hax_vcpu_state'
  accel/hax: Use 'accel_vcpu' generic pointer
  accel/kvm: Introduce kvm_vcpu_state() helper
  accel/kvm: Use kvm_vcpu_state() when possible
  accel/kvm: Declare and allocate AccelvCPUState struct
  accel/kvm: Move the 'kvm_fd' field to AccelvCPUState
  accel/kvm: Move the 'kvm_state' field to AccelvCPUState
  accel/kvm: Move the 'kvm_run' field to AccelvCPUState
  accel/hvf: Reduce deref by declaring 'hv_vcpuid_t hvf_fd' on stack
  accel/hvf: Declare and allocate AccelvCPUState struct
  accel/hvf: Move the 'hvf_fd' field to AccelvCPUState

 include/hw/core/cpu.h         |  17 +--
 include/sysemu/kvm.h          |   2 +
 include/sysemu/kvm_int.h      |   9 ++
 target/i386/hax/hax-i386.h    |  10 +-
 target/i386/hvf/hvf-i386.h    |   4 +
 target/i386/hvf/vmx.h         |  28 +++--
 accel/kvm/kvm-all.c           |  44 ++++---
 hw/s390x/pv.c                 |   3 +-
 target/arm/kvm.c              |   2 +-
 target/arm/kvm64.c            |  12 +-
 target/i386/cpu.c             |   4 +-
 target/i386/hax/hax-all.c     |  22 ++--
 target/i386/hax/hax-posix.c   |   4 +-
 target/i386/hax/hax-windows.c |   4 +-
 target/i386/hvf/hvf.c         | 118 +++++++++---------
 target/i386/hvf/x86.c         |  28 ++---
 target/i386/hvf/x86_descr.c   |  32 +++--
 target/i386/hvf/x86_emu.c     |  62 +++++-----
 target/i386/hvf/x86_mmu.c     |   4 +-
 target/i386/hvf/x86_task.c    |  14 ++-
 target/i386/hvf/x86hvf.c      | 227 +++++++++++++++++-----------------
 target/i386/kvm/kvm.c         |  36 +++---
 target/i386/whpx/whpx-all.c   |  34 ++---
 target/ppc/kvm.c              |  16 +--
 target/s390x/kvm.c            | 148 +++++++++++-----------
 25 files changed, 466 insertions(+), 418 deletions(-)

Comments

Paolo Bonzini March 4, 2021, 1:56 p.m. UTC | #1
On 03/03/21 19:22, Philippe Mathieu-Daudé wrote:
> Series is organized as:
> - preliminary trivial cleanups
> - introduce AccelvCPUState
> - move WHPX fields (build-tested)
> - move HAX fields (not tested)
> - move KVM fields (build-tested)
> - move HVF fields (not tested)

This approach prevents adding a TCG state.  Have you thought of using a 
union instead, or even a void pointer?

Paolo
Philippe Mathieu-Daudé March 4, 2021, 2:54 p.m. UTC | #2
On 3/4/21 2:56 PM, Paolo Bonzini wrote:
> On 03/03/21 19:22, Philippe Mathieu-Daudé wrote:
>> Series is organized as:
>> - preliminary trivial cleanups
>> - introduce AccelvCPUState
>> - move WHPX fields (build-tested)
>> - move HAX fields (not tested)
>> - move KVM fields (build-tested)
>> - move HVF fields (not tested)
> 
> This approach prevents adding a TCG state.  Have you thought of using a
> union instead, or even a void pointer?

Why does it prevent it? We can only have one accelerator per vCPU.

TCG state has to be declared as another AccelvCPUState implementation.

Am I missing something?

Preventing building different accelerator-specific code in the same
unit file is on purpose.

Regards,

Phil.
Paolo Bonzini March 4, 2021, 3:40 p.m. UTC | #3
On 04/03/21 15:54, Philippe Mathieu-Daudé wrote:
> On 3/4/21 2:56 PM, Paolo Bonzini wrote:
>> On 03/03/21 19:22, Philippe Mathieu-Daudé wrote:
>>> Series is organized as:
>>> - preliminary trivial cleanups
>>> - introduce AccelvCPUState
>>> - move WHPX fields (build-tested)
>>> - move HAX fields (not tested)
>>> - move KVM fields (build-tested)
>>> - move HVF fields (not tested)
>>
>> This approach prevents adding a TCG state.  Have you thought of using a
>> union instead, or even a void pointer?
> 
> Why does it prevent it? We can only have one accelerator per vCPU.

You're right, my misguided assumption was that there can only be one of 
WHPX/HAX/KVM/HVF.  This is true for WHPX/KVM/HVF but HAX can live with 
any of the others.

However this means that AccelvCPUState would have multiple definitions. 
  Did you check that gdb copes well with it?  It's also forbidden by 
C++[1], so another thing to check would be LTO when using the C++ 
compiler for linking.

Paolo

[1] https://en.wikipedia.org/wiki/One_Definition_Rule

> TCG state has to be declared as another AccelvCPUState implementation.
> 
> Am I missing something?
> 
> Preventing building different accelerator-specific code in the same
> unit file is on purpose.
> 
> Regards,
> 
> Phil.
>
Philippe Mathieu-Daudé March 4, 2021, 4:42 p.m. UTC | #4
On 3/4/21 4:40 PM, Paolo Bonzini wrote:
> On 04/03/21 15:54, Philippe Mathieu-Daudé wrote:
>> On 3/4/21 2:56 PM, Paolo Bonzini wrote:
>>> On 03/03/21 19:22, Philippe Mathieu-Daudé wrote:
>>>> Series is organized as:
>>>> - preliminary trivial cleanups
>>>> - introduce AccelvCPUState
>>>> - move WHPX fields (build-tested)
>>>> - move HAX fields (not tested)
>>>> - move KVM fields (build-tested)
>>>> - move HVF fields (not tested)
>>>
>>> This approach prevents adding a TCG state.  Have you thought of using a
>>> union instead, or even a void pointer?
>>
>> Why does it prevent it? We can only have one accelerator per vCPU.
> 
> You're right, my misguided assumption was that there can only be one of
> WHPX/HAX/KVM/HVF.  This is true for WHPX/KVM/HVF but HAX can live with
> any of the others.

I suppose you aren't talking about build-time but runtime. There should
be no distinction related to accelerator at runtime. We should be able
to have multiple accelerators at runtime, and eventually be able to
migrate vCPU from one accelerator to another, if it is proven useful.

How accelerators are orchestrated is obviously out of the scope of this
series.

> However this means that AccelvCPUState would have multiple definitions.

Yes.

>  Did you check that gdb copes well with it?

No, I haven't, because we already use opaque pointers elsewhere.

> It's also forbidden by
> C++[1], so another thing to check would be LTO when using the C++
> compiler for linking.

OK, I have no clue about C++ (and tries to keep QEMU way from it)
or about LTO. So I'd need to investigate that.

> 
> Paolo
> 
> [1] https://en.wikipedia.org/wiki/One_Definition_Rule
> 
>> TCG state has to be declared as another AccelvCPUState implementation.
>>
>> Am I missing something?
>>
>> Preventing building different accelerator-specific code in the same
>> unit file is on purpose.
>>
>> Regards,
>>
>> Phil.
>>
>