forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'x86_tdx_for_6.2' of git://git.kernel.org/pub/scm/linux/ker…
…nel/git/tip/tip Pull x86 tdx updates from Dave Hansen: "This includes a single chunk of new functionality for TDX guests which allows them to talk to the trusted TDX module software and obtain an attestation report. This report can then be used to prove the trustworthiness of the guest to a third party and get access to things like storage encryption keys" * tag 'x86_tdx_for_6.2' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: selftests/tdx: Test TDX attestation GetReport support virt: Add TDX guest driver x86/tdx: Add a wrapper to get TDREPORT0 from the TDX Module
- Loading branch information
Showing
15 changed files
with
469 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
.. SPDX-License-Identifier: GPL-2.0 | ||
=================================================================== | ||
TDX Guest API Documentation | ||
=================================================================== | ||
|
||
1. General description | ||
====================== | ||
|
||
The TDX guest driver exposes IOCTL interfaces via the /dev/tdx-guest misc | ||
device to allow userspace to get certain TDX guest-specific details. | ||
|
||
2. API description | ||
================== | ||
|
||
In this section, for each supported IOCTL, the following information is | ||
provided along with a generic description. | ||
|
||
:Input parameters: Parameters passed to the IOCTL and related details. | ||
:Output: Details about output data and return value (with details about | ||
the non common error values). | ||
|
||
2.1 TDX_CMD_GET_REPORT0 | ||
----------------------- | ||
|
||
:Input parameters: struct tdx_report_req | ||
:Output: Upon successful execution, TDREPORT data is copied to | ||
tdx_report_req.tdreport and return 0. Return -EINVAL for invalid | ||
operands, -EIO on TDCALL failure or standard error number on other | ||
common failures. | ||
|
||
The TDX_CMD_GET_REPORT0 IOCTL can be used by the attestation software to get | ||
the TDREPORT0 (a.k.a. TDREPORT subtype 0) from the TDX module using | ||
TDCALL[TDG.MR.REPORT]. | ||
|
||
A subtype index is added at the end of this IOCTL CMD to uniquely identify the | ||
subtype-specific TDREPORT request. Although the subtype option is mentioned in | ||
the TDX Module v1.0 specification, section titled "TDG.MR.REPORT", it is not | ||
currently used, and it expects this value to be 0. So to keep the IOCTL | ||
implementation simple, the subtype option was not included as part of the input | ||
ABI. However, in the future, if the TDX Module supports more than one subtype, | ||
a new IOCTL CMD will be created to handle it. To keep the IOCTL naming | ||
consistent, a subtype index is added as part of the IOCTL CMD. | ||
|
||
Reference | ||
--------- | ||
|
||
TDX reference material is collected here: | ||
|
||
https://www.intel.com/content/www/us/en/developer/articles/technical/intel-trust-domain-extensions.html | ||
|
||
The driver is based on TDX module specification v1.0 and TDX GHCI specification v1.0. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
config TDX_GUEST_DRIVER | ||
tristate "TDX Guest driver" | ||
depends on INTEL_TDX_GUEST | ||
help | ||
The driver provides userspace interface to communicate with | ||
the TDX module to request the TDX guest details like attestation | ||
report. | ||
|
||
To compile this driver as module, choose M here. The module will | ||
be called tdx-guest. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
obj-$(CONFIG_TDX_GUEST_DRIVER) += tdx-guest.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// 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 <uapi/linux/tdx-guest.h> | ||
|
||
#include <asm/cpu_device_id.h> | ||
#include <asm/tdx.h> | ||
|
||
static long tdx_get_report0(struct tdx_report_req __user *req) | ||
{ | ||
u8 *reportdata, *tdreport; | ||
long ret; | ||
|
||
reportdata = kmalloc(TDX_REPORTDATA_LEN, GFP_KERNEL); | ||
if (!reportdata) | ||
return -ENOMEM; | ||
|
||
tdreport = kzalloc(TDX_REPORT_LEN, GFP_KERNEL); | ||
if (!tdreport) { | ||
ret = -ENOMEM; | ||
goto out; | ||
} | ||
|
||
if (copy_from_user(reportdata, req->reportdata, TDX_REPORTDATA_LEN)) { | ||
ret = -EFAULT; | ||
goto out; | ||
} | ||
|
||
/* Generate TDREPORT0 using "TDG.MR.REPORT" TDCALL */ | ||
ret = tdx_mcall_get_report0(reportdata, tdreport); | ||
if (ret) | ||
goto out; | ||
|
||
if (copy_to_user(req->tdreport, tdreport, TDX_REPORT_LEN)) | ||
ret = -EFAULT; | ||
|
||
out: | ||
kfree(reportdata); | ||
kfree(tdreport); | ||
|
||
return ret; | ||
} | ||
|
||
static long tdx_guest_ioctl(struct file *file, unsigned int cmd, | ||
unsigned long arg) | ||
{ | ||
switch (cmd) { | ||
case TDX_CMD_GET_REPORT0: | ||
return tdx_get_report0((struct tdx_report_req __user *)arg); | ||
default: | ||
return -ENOTTY; | ||
} | ||
} | ||
|
||
static const struct file_operations tdx_guest_fops = { | ||
.owner = THIS_MODULE, | ||
.unlocked_ioctl = tdx_guest_ioctl, | ||
.llseek = no_llseek, | ||
}; | ||
|
||
static struct miscdevice tdx_misc_dev = { | ||
.name = KBUILD_MODNAME, | ||
.minor = MISC_DYNAMIC_MINOR, | ||
.fops = &tdx_guest_fops, | ||
}; | ||
|
||
static const struct x86_cpu_id tdx_guest_ids[] = { | ||
X86_MATCH_FEATURE(X86_FEATURE_TDX_GUEST, NULL), | ||
{} | ||
}; | ||
MODULE_DEVICE_TABLE(x86cpu, tdx_guest_ids); | ||
|
||
static int __init tdx_guest_init(void) | ||
{ | ||
if (!x86_match_cpu(tdx_guest_ids)) | ||
return -ENODEV; | ||
|
||
return misc_register(&tdx_misc_dev); | ||
} | ||
module_init(tdx_guest_init); | ||
|
||
static void __exit tdx_guest_exit(void) | ||
{ | ||
misc_deregister(&tdx_misc_dev); | ||
} | ||
module_exit(tdx_guest_exit); | ||
|
||
MODULE_AUTHOR("Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>"); | ||
MODULE_DESCRIPTION("TDX Guest Driver"); | ||
MODULE_LICENSE("GPL"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ | ||
/* | ||
* Userspace interface for TDX guest driver | ||
* | ||
* Copyright (C) 2022 Intel Corporation | ||
*/ | ||
|
||
#ifndef _UAPI_LINUX_TDX_GUEST_H_ | ||
#define _UAPI_LINUX_TDX_GUEST_H_ | ||
|
||
#include <linux/ioctl.h> | ||
#include <linux/types.h> | ||
|
||
/* Length of the REPORTDATA used in TDG.MR.REPORT TDCALL */ | ||
#define TDX_REPORTDATA_LEN 64 | ||
|
||
/* Length of TDREPORT used in TDG.MR.REPORT TDCALL */ | ||
#define TDX_REPORT_LEN 1024 | ||
|
||
/** | ||
* struct tdx_report_req - Request struct for TDX_CMD_GET_REPORT0 IOCTL. | ||
* | ||
* @reportdata: User buffer with REPORTDATA to be included into TDREPORT. | ||
* Typically it can be some nonce provided by attestation | ||
* service, so the generated TDREPORT can be uniquely verified. | ||
* @tdreport: User buffer to store TDREPORT output from TDCALL[TDG.MR.REPORT]. | ||
*/ | ||
struct tdx_report_req { | ||
__u8 reportdata[TDX_REPORTDATA_LEN]; | ||
__u8 tdreport[TDX_REPORT_LEN]; | ||
}; | ||
|
||
/* | ||
* TDX_CMD_GET_REPORT0 - Get TDREPORT0 (a.k.a. TDREPORT subtype 0) using | ||
* TDCALL[TDG.MR.REPORT] | ||
* | ||
* Return 0 on success, -EIO on TDCALL execution failure, and | ||
* standard errno on other general error cases. | ||
*/ | ||
#define TDX_CMD_GET_REPORT0 _IOWR('T', 1, struct tdx_report_req) | ||
|
||
#endif /* _UAPI_LINUX_TDX_GUEST_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
CFLAGS += -O3 -Wl,-no-as-needed -Wall -static | ||
|
||
TEST_GEN_PROGS := tdx_guest_test | ||
|
||
include ../lib.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_TDX_GUEST_DRIVER=y |
Oops, something went wrong.