Re: [kvm-unit-tests PATCH v2 3/4] x86/access: Forced emulation support

Mathias Krause
2023-04-03T09:08:49Z

On 31.03.23 18:24, Sean Christopherson wrote:
> On Fri, Mar 31, 2023, Mathias Krause wrote:
>> Add support to enforce access tests to be handled by the emulator, if
>> supported by KVM. Exclude it from the ac_test_exec() test, though, to
>> not slow it down too much.
>
> /enthusiastic high five

*clap*

>
> I was going to ask if you could extend the test to utilize FEP, and woke up this
> morning to see it already done. Thanks!!!!!
>
>> Signed-off-by: Mathias Krause <minipli@grsecurity.net>
>> ---
>
> ...
>
>> @@ -152,6 +161,7 @@ const char *ac_names[] = {
>> [AC_CPU_CR0_WP_BIT] = "cr0.wp",
>> [AC_CPU_CR4_SMEP_BIT] = "cr4.smep",
>> [AC_CPU_CR4_PKE_BIT] = "cr4.pke",
>> + [AC_FEP_BIT] = "fep",
>> };
>>
>> static inline void *va(pt_element_t phys)
>> @@ -190,6 +200,7 @@ typedef struct {
>>
>> static void ac_test_show(ac_test_t *at);
>>
>> +static bool fep_available;
>
> I don't think fep_available needs to be captured in a global bool, the usage in
> the CR0_WP test can do
>
> if (invalid_mask & AC_FEP_MASK)
> <skip>

Ok, makes it a little uglier, IMHO, but will change.

Again, I was just looking at other tests and copied what I thought was
sensible. But looking at x86/emulator.c again, I see it's not consistent
either. It caches the value in test_mov_pop_ss_code_db() but does not in
main().

Maybe I should just use is_fep_available() twice as well, as the
additional exception handling shouldn't matter much.

Thanks,
Mathias