linux/drivers/virt/coco/tdx-guest/tdx-guest.c

// SPDX-License-Identifier: GPL-2.0
/*
 * TDX guest user interface driver
 *
 * Copyright (C) 2022 Intel Corporation
 */

#include <linux/kernel.h>
#include <linux/miscdevice.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/string.h>
#include <linux/uaccess.h>
#include <linux/set_memory.h>
#include <linux/io.h>
#include <linux/delay.h>
#include <linux/tsm.h>
#include <linux/sizes.h>

#include <uapi/linux/tdx-guest.h>

#include <asm/cpu_device_id.h>
#include <asm/tdx.h>

/*
 * Intel's SGX QE implementation generally uses Quote size less
 * than 8K (2K Quote data + ~5K of certificate blob).
 */
#define GET_QUOTE_BUF_SIZE

#define GET_QUOTE_CMD_VER

/* TDX GetQuote status codes */
#define GET_QUOTE_SUCCESS
#define GET_QUOTE_IN_FLIGHT

/* struct tdx_quote_buf: Format of Quote request buffer.
 * @version: Quote format version, filled by TD.
 * @status: Status code of Quote request, filled by VMM.
 * @in_len: Length of TDREPORT, filled by TD.
 * @out_len: Length of Quote data, filled by VMM.
 * @data: Quote data on output or TDREPORT on input.
 *
 * More details of Quote request buffer can be found in TDX
 * Guest-Host Communication Interface (GHCI) for Intel TDX 1.0,
 * section titled "TDG.VP.VMCALL<GetQuote>"
 */
struct tdx_quote_buf {};

/* Quote data buffer */
static void *quote_data;

/* Lock to streamline quote requests */
static DEFINE_MUTEX(quote_lock);

/*
 * GetQuote request timeout in seconds. Expect that 30 seconds
 * is enough time for QE to respond to any Quote requests.
 */
static u32 getquote_timeout =;

static long tdx_get_report0(struct tdx_report_req __user *req)
{}

static void free_quote_buf(void *buf)
{}

static void *alloc_quote_buf(void)
{}

/*
 * wait_for_quote_completion() - Wait for Quote request completion
 * @quote_buf: Address of Quote buffer.
 * @timeout: Timeout in seconds to wait for the Quote generation.
 *
 * As per TDX GHCI v1.0 specification, sec titled "TDG.VP.VMCALL<GetQuote>",
 * the status field in the Quote buffer will be set to GET_QUOTE_IN_FLIGHT
 * while VMM processes the GetQuote request, and will change it to success
 * or error code after processing is complete. So wait till the status
 * changes from GET_QUOTE_IN_FLIGHT or the request being timed out.
 */
static int wait_for_quote_completion(struct tdx_quote_buf *quote_buf, u32 timeout)
{}

static int tdx_report_new(struct tsm_report *report, void *data)
{}

static bool tdx_report_attr_visible(int n)
{}

static bool tdx_report_bin_attr_visible(int n)
{}

static long tdx_guest_ioctl(struct file *file, unsigned int cmd,
			    unsigned long arg)
{}

static const struct file_operations tdx_guest_fops =;

static struct miscdevice tdx_misc_dev =;

static const struct x86_cpu_id tdx_guest_ids[] =;
MODULE_DEVICE_TABLE(x86cpu, tdx_guest_ids);

static const struct tsm_ops tdx_tsm_ops =;

static int __init tdx_guest_init(void)
{}
module_init();

static void __exit tdx_guest_exit(void)
{}
module_exit(tdx_guest_exit);

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();