On Wed, Aug 24, 2022, Michal Luczaj wrote: > On 8/24/22 20:32, Sean Christopherson wrote: > > Eh, let's completely skip usermode for code #DBs and not tweak __run_single_step_db_test(). > > It's easier to just have a standalone function. > > Something like this? > > static void test_pop_ss_code_db(bool fep_available) > { > write_ss(KERNEL_DS); > > write_dr7(DR7_FIXED_1 | > DR7_ENABLE_DRx(0) | > DR7_EXECUTE_DRx(0) | > DR7_LEN_1_DRx(0)); > > #define POPSS_DB(desc, fep1, fep2) \ > ({ \ > unsigned int r; \ > \ > n = 0; \ > asm volatile(/* jump to 32-bit code segment */ \ > "ljmp *1f\n\t" \ > "1:\n\t" \ > " .long 2f\n\t" \ > " .word " xstr(KERNEL_CS32) "\n\t" \ > /* exercise POP SS blocking */ \ > ".code32\n\t" \ > "2: lea 3f, %0\n\t" \ > "mov %0, %%dr0\n\t" \ > "push %%ss\n\t" \ > fep1 "pop %%ss\n\t" \ > fep2 "3: xor %0, %0\n\t" \ > /* back to long mode */ \ > "ljmp %[cs64], $4f\n\t" \ > ".code64\n\t" \ Ooh, I see what you meant by temporarily switching to 32-bit mode. I was thinking we could just make the POP SS testcase 32-bit only, but I didn't realize this test is 64-bit only. Argh, and so is emulate.c. And now I get why you added a brand new test. Let's just add a new test. The above can work, but it relies on the code and stack being mapped with a 32-bit address, e.g. will break if KUT is ever changed to not map everything low in the virtual address space. I think it makes sense to rename emulator.c => emulator64.c, and then start a new emulator.c for tests that apply to both 32-bit and 64-bit KUT. I'll send a small series, the behavior is also different for AMD CPUs (I coded up 99% of this yesterday before realizing this morning that debug.c is 64-bit only).