Skip to content

Commit

Permalink
Add pre_condition for related cases.
Browse files Browse the repository at this point in the history
that exiting map is ~PERFMON.

Signed-off-by: Dongcheng Yan <[email protected]>
  • Loading branch information
CrescentLove committed Aug 3, 2023
1 parent 181fc96 commit 40668b7
Showing 1 changed file with 82 additions and 12 deletions.
94 changes: 82 additions & 12 deletions tdx-compliance/tdx-compliance-msr.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,22 @@
#define RESERVED_0X1981 0x1981

/* pre-conditions */
static void pre_perfmon(struct test_msr *c)
{
static int _get_perfmon() {
/* PERFMON: CPUID(0xa).* */
struct test_cpuid cpt = DEF_CPUID_TEST(0xa, 0);

run_cpuid(&cpt);

if (cpt.regs.eax.val == 0 && cpt.regs.ebx.val == 0 &&
cpt.regs.ecx.val == 0 && cpt.regs.edx.val == 0)
return 0;

return 1;
}

static void pre_perfmon(struct test_msr *c)
{
if (!_get_perfmon())
c->excp.expect = X86_TRAP_GP;
}

Expand Down Expand Up @@ -223,6 +230,69 @@ static void pre_tsx(struct test_msr *c)
}
}

static void pre_fixedctr(struct test_msr *c)
{
struct test_cpuid cpt = DEF_CPUID_TEST(0xa, 0x0);

run_cpuid(&cpt);
if (!_get_perfmon() || (cpt.regs.edx.val & 0x1f) == 0)
c->excp.expect = X86_TRAP_GP;
}

static void pre_09a0(struct test_msr *c)
{
if (!_get_perfmon()) {
c->excp.expect = X86_TRAP_GP;
return;
}
struct test_cpuid cpt1 = DEF_CPUID_TEST(0x7, 0x1);
struct test_cpuid cpt2 = DEF_CPUID_TEST(0x23, 0x0);
struct test_cpuid cpt3 = DEF_CPUID_TEST(0x23, 0x2);
run_cpuid(&cpt1);
run_cpuid(&cpt2);
run_cpuid(&cpt3);

if (!((cpt1.regs.eax.val & _BITUL(8)) == 1 &&
(cpt2.regs.eax.val & _BITUL(2)) == 1 && cpt3.regs.ebx.val == 1))
c->excp.expect = X86_TRAP_VE;
}

static void pre_09c0(struct test_msr *c)
{
if (!_get_perfmon()) {
c->excp.expect = X86_TRAP_GP;
return;
}
struct test_cpuid cpt1 = DEF_CPUID_TEST(0x7, 0x1);
struct test_cpuid cpt2 = DEF_CPUID_TEST(0x23, 0x0);
struct test_cpuid cpt3 = DEF_CPUID_TEST(0x23, 0x2);
run_cpuid(&cpt1);
run_cpuid(&cpt2);
run_cpuid(&cpt3);

if (!((cpt1.regs.eax.val & _BITUL(8)) == 1 &&
(cpt2.regs.eax.val & _BITUL(2)) == 1 && cpt3.regs.ebx.val == 2))
c->excp.expect = X86_TRAP_VE;
}

static void pre_09e0_09f0(struct test_msr *c)
{
if (!_get_perfmon()) {
c->excp.expect = X86_TRAP_GP;
return;
}
struct test_cpuid cpt1 = DEF_CPUID_TEST(0x7, 0x1);
struct test_cpuid cpt2 = DEF_CPUID_TEST(0x23, 0x0);
struct test_cpuid cpt3 = DEF_CPUID_TEST(0x23, 0x2);
run_cpuid(&cpt1);
run_cpuid(&cpt2);
run_cpuid(&cpt3);

if (!((cpt1.regs.eax.val & _BITUL(8)) == 1 &&
(cpt2.regs.eax.val & _BITUL(2)) == 1 && cpt3.regs.eax.val == 1))
c->excp.expect = X86_TRAP_VE;
}

struct test_msr msr_cases[] = {
DEF_READ_MSR(MSR_IA32_TSC, NO_EXCP, NO_PRE_COND),
DEF_WRITE_MSR(MSR_IA32_TSC, X86_TRAP_VE, NO_PRE_COND),
Expand Down Expand Up @@ -283,8 +353,8 @@ struct test_msr msr_cases[] = {
DEF_WRITE_MSR(MSR_SLAM_ENABLE, X86_TRAP_GP, NO_PRE_COND),
DEF_READ_MSR(MSR_IA32_CR_PAT, NO_EXCP, NO_PRE_COND),
DEF_WRITE_MSR(MSR_IA32_CR_PAT, NO_EXCP, NO_PRE_COND),
DEF_READ_MSR_SIZE(MSR_CORE_PERF_FIXED_CTR0, NO_EXCP, pre_perfmon, 0x8),
DEF_WRITE_MSR_SIZE(MSR_CORE_PERF_FIXED_CTR0, NO_EXCP, pre_perfmon, 0x8),
DEF_READ_MSR_SIZE(MSR_CORE_PERF_FIXED_CTR0, NO_EXCP, pre_fixedctr, 0x8),
DEF_WRITE_MSR_SIZE(MSR_CORE_PERF_FIXED_CTR0, NO_EXCP, pre_fixedctr, 0x8),
DEF_READ_MSR(MSR_PERF_METRICS, NO_EXCP, pre_perfmon),
DEF_WRITE_MSR(MSR_PERF_METRICS, NO_EXCP, pre_perfmon),

Expand Down Expand Up @@ -500,12 +570,12 @@ struct test_msr msr_cases[] = {
DEF_READ_MSR(RESERVED_0X1981, X86_TRAP_GP, NO_PRE_COND),
DEF_WRITE_MSR(RESERVED_0X1981, X86_TRAP_GP, NO_PRE_COND),

DEF_READ_MSR_SIZE(RESERVED_0X09A0, NO_EXCP, pre_perfmon, 0x4),
DEF_WRITE_MSR_SIZE(RESERVED_0X09A0, NO_EXCP, pre_perfmon, 0x4),
DEF_READ_MSR_SIZE(RESERVED_0X09C0, NO_EXCP, pre_perfmon, 0x4),
DEF_WRITE_MSR_SIZE(RESERVED_0X09C0, NO_EXCP, pre_perfmon, 0x4),
DEF_READ_MSR_SIZE(RESERVED_0X09E0, NO_EXCP, pre_perfmon, 0x8),
DEF_WRITE_MSR_SIZE(RESERVED_0X09E0, NO_EXCP, pre_perfmon, 0x8),
DEF_READ_MSR_SIZE(RESERVED_0X09F0, NO_EXCP, pre_perfmon, 0x8),
DEF_WRITE_MSR_SIZE(RESERVED_0X09F0, NO_EXCP, pre_perfmon, 0x8),
DEF_READ_MSR_SIZE(RESERVED_0X09A0, NO_EXCP, pre_09a0, 0x4),
DEF_WRITE_MSR_SIZE(RESERVED_0X09A0, NO_EXCP, pre_09a0, 0x4),
DEF_READ_MSR_SIZE(RESERVED_0X09C0, NO_EXCP, pre_09c0, 0x4),
DEF_WRITE_MSR_SIZE(RESERVED_0X09C0, NO_EXCP, pre_09c0, 0x4),
DEF_READ_MSR_SIZE(RESERVED_0X09E0, NO_EXCP, pre_09e0_09f0, 0x8),
DEF_WRITE_MSR_SIZE(RESERVED_0X09E0, NO_EXCP, pre_09e0_09f0, 0x8),
DEF_READ_MSR_SIZE(RESERVED_0X09F0, NO_EXCP, pre_09e0_09f0, 0x8),
DEF_WRITE_MSR_SIZE(RESERVED_0X09F0, NO_EXCP, pre_09e0_09f0, 0x8),
};

0 comments on commit 40668b7

Please sign in to comment.