Repository navigation
kernel/protocols: Introduce OMP support - #1138
n-ramacciotti wants to merge 14 commits into
Conversation
7fc1d46 to
bb9de70
Compare
|
Is this meant to be a Coconut specific protocol or a general any SVSM implementation protocol. If the latter, then it needs to be worked out properly and added to the SVSM specification. If the former, then it will need to use one of the reserved reference implementation protocol numbers and needs to be documented for Coconut. |
|
v2:
|
@tlendacky This is part of my work for google summer of code in the coconut-svsm[1]. This is based on the draft proposal of @joergroedel posted in the mailing list [2]. I believe this will be general for any SVSM implementation protocol. Sorry for not mentioning this earlier in the PR description. Now it's updated. [1] https://wiki.qemu.org/Google_Summer_of_Code_2026 |
The discussion on the protocol died off without conclusion, so I'll use the opportunity to resume it here. I still think it makes sense to include some information what type of data is returned by a source in the SVSM_OCP_LIST reply (i.e. what became The other two ideas from my mail ( |
bb9de70 to
aafa334
Compare
|
v3:
|
aafa334 to
23bae4b
Compare
|
v4:
|
23bae4b to
27937c4
Compare
|
v5:
|
27937c4 to
0b6a3b6
Compare
|
v6:
Todo:
|
0b6a3b6 to
bd920a3
Compare
|
v7:
Todo:
|
bd920a3 to
95ba3d2
Compare
|
v8:
TODO:
|
95ba3d2 to
65b5a74
Compare
|
v9:
note: there is a commit marked with test as:
Other than that, the PR is ready for review. |
kraxel
left a comment
There was a problem hiding this comment.
Some minor comments, looks good to me overall.
65b5a74 to
a24d56d
Compare
c95166f to
50d6162
Compare
|
v16:
TODO:
|
fffe718 to
48d4aff
Compare
|
v17:
TODO:
|
48d4aff to
7d16ecc
Compare
|
v18:
|
7d16ecc to
49126e8
Compare
|
v19:
|
Thanks a lot for moving this forward! After some more discussion with the various stakeholders we made the decision to rename the protocol from OCP to OMP (Observeability and Management Protocol). Can you please use the new name in the PR? |
The new observability and configuration protocol requires an additional register `r9` to exchange data between svsm and the guest os. Add it to the `RequestParams` structure to fulfill this requirement. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Link the new Observability and Management Protocol (OMP) to the correct handler during request processing. Since a different protocol name was introduced in a previous commit, update the reserved name to the new version. Fixes: a8c0fea ("kernel/protocols: Reserve OCP number") Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Add a new structure, based on OMP protocol specifications. A source entry has a 4-byte bitfield flag field, where the least significant bit specifies if a sources is writable or not. The other bits are reserved. Also include a 2-byte `kind` field to store information on the source type. This will help the guest understand which data is transmitted and the dimension required for the buffer to store these values. A 2-byte padding is added and each entry should be exactly 128-bytes, so the remaining space is left for a human readable name (utf-8 encoded). Introduce a new const constructor which can be used for initializing a source. This function will fail if the name is greater than or equal to all its reserved bytes, as we want the name to be null terminated. If the name is less than that value, it will be padded with zeros. It will also fail if the name contains a '/', as this is used in the protocol calls to group objects and sources. As these sources will be passed to the linux guest, it is useful to derive `IntoBytes` and `Immutable` for the transfer. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Add two new traits, one for object and one for sources. Each object and source must implement the corresponding one to be added to the protocol. The traits include default implementations for the `read` and `write` methods, as each object or source may not have that functionality, in which case an error is returned. The traits also include the `for_each_source` method to iterate over the sources of an object and apply a callback to each of them. This can be used for incrementally assembling the reply to the guest OS. As it may be useful to stop the iteration early, the callback returns a boolean value that the method can use for this purpose. To keep `OmpObject` dyn-compatible, the callback in `for_each_source` must avoid generics. Therefore, use dynamic dispatch with mutable state as it may be useful to mutate it, such as the number of entries written. Use a type alias for the callback to avoid the type complexity highlighted by Clippy. Require the `Sync` bound as we want to share objects between threads safely. Require `Send` and `Debug` for completeness. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Add a vec to keep track of all the objects that implement the new trait. Since most of the access are read, use `RWLock` to lock the access to the vec. Add utilities to interact with objects. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
The protocol uses OMP names to request sources or objects. A single name is sufficient for objects, but sources require an identifier composed of both the object and source names separated by '/'. The guest OS puts the GPA of the name in the request parameters. Add two utility functions to retrieve the name and extract the corresponding source or object. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Add the new call identifier (`0`) to the OMP handler and implement `SVSM_OMP_LIST` following the spec. If some guest params are incorrect, like buffer alignment or zero bytes requested, an appropriate error will be returned. The buffer len is 4-bytes, so make sure to use only the low 32 bits. Compute the number of entries required and use `GuestPtr<[T]>` to access safely the untrusted guest region. Once an entry is available, it is possible to copy it directly to the guest memory without using temporary heap allocation to store all the entries together. As this call requires SVSM to provide a list of entries, use the new helpers to extract objects and sources. Failing to write an entry in the guest memory results in a log message, as other entries may have already been written and the result can therefore be shared with the guest. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Add the new call identifier (`1`) to the OMP handler and implement `SVSM_OMP_READ` following the spec. Use the new utility to extract the source and check if the provided parameters are correct. Since each source is required to implement the `OmpSource` trait, the read method can be used directly. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Add the new call identifier (`2`) to the OMP handler and implement `SVSM_OMP_WRITE` following the spec. Use the new utility to extract the source and check if the provided parameters are correct. Since each source is required to implement the `OmpSource` trait, the write method can be used directly. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
The query protocol is used to check the availability of a protocol at a given version. It should take into account every available protocol. Add the new OMP protocol management. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Add `observability` feature to conditionally compile the new protocol. Add it to `FEATURES_TEST` to enable it by default on test builds. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Add basic description of the new protocol. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
OMP sources shares data with the guest. Some of them, like the log buffer, are file based. The `Buffer` trait let exchange data between a file and a buffer. Add an implementation of the `Buffer` trait for accessing guest memory. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Introduce a new object which can contain some sources, implement the trait and create a new instance which is inserted in the vec. Introduce a read only source that only returns a static string containing the current SVSM version. Add a log buffer source to extract log messages. This commit will be dropped and it used only to test the infrastructure. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
49126e8 to
7c4cb92
Compare
|
v20:
No functional changes |
A guest OS, running inside a CVM does not know the state information, such as log data or memory usage, of the SVSM. These sources of information could be useful for the guest OS to understand the environment it is running in. It might also be useful for the guest OS to be able to configure some of these sources.
A new protocol, called Observability and Management Protocol (OMP), has been defined to enable information to be retrieved from an SVSM source, and to allow the configuration of sources in SVSM. All the sources and source categories available in SVSM can be listed using this protocol, and each of them can be read and potentially written.
In this PR the SVSM side of the protocol is implemented.
More details can be found in the commit messages.
Linux Device Driver: see Add support for OCP protocol linux#20
note: This require the vm to have a custom guest kernel with the above commits.
Userspace utility: see Add first version of svsm-tools n-ramacciotti/svsm-tools#1
Tested on a SNP machine. (Thanks @joergroedel )
/cc @stefano-garzarella @kraxel
This started as part of my work for Google Summer of code [1] based on the draft protocol posted in the mailing list [2]. An update version of the proposal is in one commit of this PR that updates the documentation.
[1] https://wiki.qemu.org/Google_Summer_of_Code_2026
[2] https://lore.kernel.org/coconut-svsm/aeiLnWdClMC6YuLi@sirius.home.kraxel.org/T/#t