Skip to content

Commit b4575e7

Browse files
niuyongwenchench246
authored andcommitted
[optimization]: crypto: ccp: add "tdm_guard" as kernel and module parameter
The parameter 'tdm_guard' has been implemented to provide runtime control over the TDM guard feature. As kernel boot parameter: While CONFIG_TDM_KERNEL_GUARD=y enables the feature by default, specifying: 1. 'tdm_guard=on' maintains the protection 2. 'tdm_guard=off' disables the guard mechanism" As module parameter: 1. 'modprobe tdm-kernel-guard tdm_guard=on' open the protection 2. 'modprobe tdm-kernel-guard tdm_guard=off' close the guard mechanism" Change-Id: I7dcd8a6d05d8d546a24be86a03c5cae0ca87c399 Signed-off-by: niuyongwen <niuyongwen@hygon.cn> Signed-off-by: chench <chench@hygon.cn>
1 parent 5127c23 commit b4575e7

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

drivers/crypto/ccp/hygon/tdm-kernel-guard.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,33 @@
2323
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2424

2525
static int eh_obj = -1;
26+
static char *tdm_guard;
2627
module_param(eh_obj, int, 0644);
27-
MODULE_PARM_DESC(eh_obj, "security enhance object for TDM");
28+
MODULE_PARM_DESC(eh_obj,
29+
"Bitmap of kernel targets protected by Hygon TDM(bit0: SCT, bit1: IDT, default: both)");
30+
module_param(tdm_guard, charp, 0644);
31+
MODULE_PARM_DESC(tdm_guard,
32+
"Enable TDM protection for selected targets(on=enable, off=disable, default:off)");
33+
34+
static bool tdm_guard_enabled;
35+
36+
static int __init parse_tdm_guard(char *str)
37+
{
38+
if (!str)
39+
return 0;
40+
41+
if (!strncmp(str, "off", 3)) {
42+
tdm_guard_enabled = false;
43+
pr_info("Hygon TDM Guard: Disabled(cmdline)\n");
44+
} else if (!strncmp(str, "on", 2)) {
45+
tdm_guard_enabled = true;
46+
pr_info("Hygon TDM Guard: Enabled(cmdline)\n");
47+
}
48+
49+
return 0;
50+
}
51+
52+
__setup("tdm_guard=", parse_tdm_guard);
2853

2954
/* Objects are protected by TDM now
3055
* SCT: 0
@@ -292,6 +317,16 @@ static int __init kernel_security_enhance_init(void)
292317
goto end;
293318
}
294319

320+
if (tdm_guard) {
321+
if (!strncmp(tdm_guard, "off", 3))
322+
tdm_guard_enabled = false;
323+
else if (!strncmp(tdm_guard, "on", 2))
324+
tdm_guard_enabled = true;
325+
}
326+
327+
if (tdm_guard_enabled == false)
328+
goto end;
329+
295330
asm("sidt %0":"=m"(idtr));
296331

297332
if (!psp_check_tdm_support())
@@ -327,6 +362,9 @@ static void __exit kernel_security_enhance_exit(void)
327362
{
328363
int i = 0;
329364

365+
if (tdm_guard_enabled == false)
366+
return;
367+
330368
if (!psp_check_tdm_support())
331369
return;
332370

0 commit comments

Comments
 (0)