Skip to content

Commit

Permalink
x86/tdx: Add command line option to disable TDX guest filter support
Browse files Browse the repository at this point in the history
Add a kernel command line option to disable device filter support
for TDX guest platform. It is a debug feature.

Reviewed-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
  • Loading branch information
Kuppuswamy Sathyanarayanan committed Jun 25, 2021
1 parent d1f2bc6 commit 513d3c2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Documentation/admin-guide/kernel-parameters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5491,6 +5491,9 @@
Disable automatic kernel lockdown for TD guest.
Only allowed for debug TD.

tdx_disable_filter [x86]
Disable TDX guest filter support.

test_suspend= [SUSPEND][,N]
Specify "mem" (for Suspend-to-RAM) or "standby" (for
standby suspend) or "freeze" (for suspend type freeze)
Expand Down
2 changes: 2 additions & 0 deletions arch/x86/include/asm/tdx.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ extern phys_addr_t tdg_shared_mask(void);
extern int tdx_hcall_gpa_intent(phys_addr_t gpa, int numpages,
enum tdx_map_type map_type);

bool tdg_filter_enabled(void);

/*
* To support I/O port access in decompressor or early kernel init
* code, since #VE exception handler cannot be used, use paravirt
Expand Down
20 changes: 20 additions & 0 deletions arch/x86/kernel/tdx-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <linux/protected_guest.h>

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

#define ADD_FILTER_NODE(bname, alist, st) \
{ \
Expand Down Expand Up @@ -47,13 +48,32 @@ static struct drv_filter_node filter_list[] = {
ADD_FILTER_NODE(virtio, virtio_allow_list, false),
};

bool tdg_filter_enabled(void)
{
static bool cmdline_scan;
static bool filter_status;

if (!cmdline_scan) {
filter_status = cmdline_find_option_bool(boot_command_line,
"tdx_disable_filter");
cmdline_scan = true;
}

return !filter_status;
}

void __init tdg_filter_init(void)
{
int i;

if (!prot_guest_has(PR_GUEST_TDX))
return;

if (!tdg_filter_enabled()) {
pr_info("Disabled TDX guest filter support\n");
return;
}

for (i = 0; i < ARRAY_SIZE(filter_list); i++)
register_drv_filter(&filter_list[i]);

Expand Down
5 changes: 4 additions & 1 deletion arch/x86/kernel/tdx.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,17 @@ static inline bool cpuid_has_tdx_guest(void)

bool tdx_prot_guest_has(unsigned long flag)
{
bool tdx_guest_enabled = cpu_feature_enabled(X86_FEATURE_TDX_GUEST);

switch (flag) {
case PR_GUEST_MEM_ENCRYPT:
case PR_GUEST_MEM_ENCRYPT_ACTIVE:
case PR_GUEST_UNROLL_STRING_IO:
case PR_GUEST_SHARED_MAPPING_INIT:
case PR_GUEST_TDX:
return tdx_guest_enabled;
case PR_GUEST_DRIVER_FILTER:
return cpu_feature_enabled(X86_FEATURE_TDX_GUEST);
return tdg_filter_enabled() && tdx_guest_enabled;
}

return false;
Expand Down

0 comments on commit 513d3c2

Please sign in to comment.