KVM: PPC: Add helper library for Guest State Buffers
authorJordan Niethe <jniethe5@gmail.com>
Thu, 14 Sep 2023 03:05:57 +0000 (13:05 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 14 Sep 2023 12:04:24 +0000 (22:04 +1000)
commit6ccbbc33f06adaf79acde18571c6543ad1cb4be6
tree6b520b5b10268c5f4e0a809bd38ae78e792d70f7
parent6de2e837babb411cfb3cdb570581c3a65576ddaf
KVM: PPC: Add helper library for Guest State Buffers

The PAPR "Nestedv2" guest API introduces the concept of a Guest State
Buffer for communication about L2 guests between L1 and L0 hosts.

In the new API, the L0 manages the L2 on behalf of the L1. This means
that if the L1 needs to change L2 state (e.g. GPRs, SPRs, partition
table...), it must request the L0 perform the modification. If the
nested host needs to read L2 state likewise this request must
go through the L0.

The Guest State Buffer is a Type-Length-Value style data format defined
in the PAPR which assigns all relevant partition state a unique
identity. Unlike a typical TLV format the length is redundant as the
length of each identity is fixed but is included for checking
correctness.

A guest state buffer consists of an element count followed by a stream
of elements, where elements are composed of an ID number, data length,
then the data:

  Header:

   <---4 bytes--->
  +----------------+-----
  | Element Count  | Elements...
  +----------------+-----

  Element:

   <----2 bytes---> <-2 bytes-> <-Length bytes->
  +----------------+-----------+----------------+
  | Guest State ID |  Length   |      Data      |
  +----------------+-----------+----------------+

Guest State IDs have other attributes defined in the PAPR such as
whether they are per thread or per guest, or read-only.

Introduce a library for using guest state buffers. This includes support
for actions such as creating buffers, adding elements to buffers,
reading the value of elements and parsing buffers. This will be used
later by the nestedv2 guest support.

Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230914030600.16993-9-jniethe5@gmail.com
arch/powerpc/Kconfig.debug
arch/powerpc/include/asm/guest-state-buffer.h [new file with mode: 0644]
arch/powerpc/kvm/Makefile
arch/powerpc/kvm/guest-state-buffer.c [new file with mode: 0644]
arch/powerpc/kvm/test-guest-state-buffer.c [new file with mode: 0644]