Skip to content

Add support for OCP protocol - #20

Open
n-ramacciotti wants to merge 4 commits into
coconut-svsm:svsmfrom
n-ramacciotti:ocp_module
Open

Add support for OCP protocol#20
n-ramacciotti wants to merge 4 commits into
coconut-svsm:svsmfrom
n-ramacciotti:ocp_module

Conversation

@n-ramacciotti

@n-ramacciotti n-ramacciotti commented Jun 24, 2026

Copy link
Copy Markdown

RFC PR for observability and configuration protocol

This is the linux-side handler.

It contains the platform device and driver registration + all the ocp calls implementation.

This contains a [test] commit with a module that can be loaded and will do a single call to SVSM_OCP_LIST during initialization. The parameter of this call can be changed based on a configuration parameter that can be specified when inserting the module. This can be inserted and removed multiple times.

see PR coconut-svsm/svsm#1138 and n-ramacciotti/svsm-tools#1

@n-ramacciotti

Copy link
Copy Markdown
Author

v2:

  • Introduced support for read and write
  • Introduced testing for write operation

@n-ramacciotti
n-ramacciotti force-pushed the ocp_module branch 8 times, most recently from 7c5394b to 1b7a412 Compare July 8, 2026 11:48
@n-ramacciotti

n-ramacciotti commented Jul 22, 2026

Copy link
Copy Markdown
Author

v3:

  • updated svsm calls to account for the two list functionalities
  • add platform driver with basic registration and memory allocation (similarly to vtpm)
  • add platform device (similarly to vtpm)

TODO:

  • add ioctl interface

@n-ramacciotti

n-ramacciotti commented Jul 24, 2026

Copy link
Copy Markdown
Author

v4:

  • added ioctl interface
  • formatted based on scripts/checkpatch.pl feedback:
    • used kzalloc_obj instead of kzalloc
    • other formatting issues

Tested locally (without SNP, but with fake replies and a very basic userspace application)

TODO:

  • test with snp
  • Introduce userspace application (will be in a separate repository)
  • for the moment one ioctl call is one svsm call, but it is possible to query svsm multiple times if user requires more bytes than max allowed in a single svsm call
  • return bytes_read/written, number of sources/object as ioctl return value instead of 0?
  • write call in ioctl is a copy-paste of read and should be fixed
  • Does it make sense to keep "Source" and "Details" in uapi? As these are not used by kernel but only by svsm and guest

@n-ramacciotti
n-ramacciotti force-pushed the ocp_module branch 4 times, most recently from 9b25fc1 to 8326c56 Compare July 28, 2026 10:03
@n-ramacciotti

n-ramacciotti commented Jul 28, 2026

Copy link
Copy Markdown
Author

v5:

  • added WITH Linux-syscall-note in ocp_svsm.h
  • fixed typo in list_object_sources where list_objects was used instead of list_sources
  • Add support for missing struct in uapi (object_details)
  • Add size assertion in uapi
  • Fixed write source call
  • As the argp of ioctl contains both in/out args, change the ioclt to use _IOWR
    Other todo in Add support for OCP protocol #20 (comment) are open

@n-ramacciotti
n-ramacciotti force-pushed the ocp_module branch 4 times, most recently from 0c38f34 to 749b2ba Compare July 30, 2026 14:03
@n-ramacciotti

Copy link
Copy Markdown
Author

v6:

  • ioctl now returns a positive integer for success
  • refactored ioctl in multiple functions
  • removed "sources" and "objects" from uapi

@n-ramacciotti
n-ramacciotti marked this pull request as ready for review August 7, 2026 16:09
@n-ramacciotti

n-ramacciotti commented Aug 7, 2026

Copy link
Copy Markdown
Author

v7:

  • updated commits
  • removed struct device and dev_t from struct ocp_dev. I believe (more info in the commit) it is correct to free the struct directly in remove instead of linking it to the lifetime of a device embedded in ocp_dev.
  • used platform_driver_probe instead of module to create class and dev_t out of probe in module init as they are not directly related to probe

It's ready for review now

Comment thread drivers/char/ocp_svsm.c Outdated
Comment thread drivers/char/ocp_svsm.c Outdated
Comment thread drivers/char/ocp_svsm.c
Comment thread drivers/char/ocp_svsm.c Outdated
@n-ramacciotti

n-ramacciotti commented Aug 13, 2026

Copy link
Copy Markdown
Author

v8:

  • Check bytes_to_read/write before calling svsm APIs

TODO:

  • Change num_entries in bytes_required

Add four new functionalities to interact with the SVSM Observability and
Configuration Protocol (OCP). They are based on the specifications draft.

Expose them so they can be used by a driver.

Signed-off-by: Nicola Ramacciotti <[email protected]>
Add a driver for the OCP defined by the spec. For now, it only supports
open. Additional file operations will be added later.

The device cannot be hot-plugged as it is emulated by the platform, so we
can use platform_driver_probe().

The module needs to create a class and obtain a range of device numbers.
These actions are not strictly related to driver probing. Therefore, avoid
the use of module_platform_driver_probe() and use module_init/exit to take
care of them.

The device will be registered by the platform only when it's available, so
probe() needs to initialize the cdev, allocate the buffer for SVSM-kernel
communications and create the device node for userspace.

Since the platform device cannot be hot-plugged, the driver has no unbind
attribute and the driver can be removed only with rmmod, which can only be
called when there are no file descriptors open. Therefore, the allocated
data can be removed directly in remove() and there is no need to have the
struct cdev and the struct device as member of the same structure with
lifetime managed by the struct device, with a custom release operation that
frees the data.

Signed-off-by: Nicola Ramacciotti <[email protected]>
@n-ramacciotti

Copy link
Copy Markdown
Author

v9:

  • changed num_entries into buf_size

@n-ramacciotti
n-ramacciotti force-pushed the ocp_module branch 2 times, most recently from 6f2ad00 to d4f2585 Compare August 18, 2026 17:10
Reserve a range of codes from the ioctl documentation. For now, only four
are needed, but some are left for growth.

Introduce the ioctl interface, which uses the API exposed by x86/sev to
send commands and receive responses from SVSM as defined in the spec.

Share the interface with uapi to make it available also for userspace.

The ioctl returns a positive integer to userspace to number of bytes.
This is done to avoid an additional copy_to_user().

Signed-off-by: Nicola Ramacciotti <[email protected]>
Add `ocp-svsm` device that can be handled by the platform driver added in
the previous commits in `drivers/char/ocp_svsm.c`

TODO:
Register the platform device only when SVSM is available and it supports
OCP calls.

Signed-off-by: Nicola Ramacciotti <[email protected]>
Comment thread arch/x86/coco/sev/svsm.c
if (ret < 0)
return ret;

*bytes_read = call.r8_out;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some calls return the bytes transfered in rcx, some in r8.
I think we should pick one register and use that everywhere.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants